1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

[ticket/11103] Create user loader class, update for DIC

Create a very basic user loader class to handle querying/storing
user data in a centralized location.

Use DIC collection service for notification types/methods.

Cleanup unused dependencies.

Fix some other issues.

PHPBB3-11103
This commit is contained in:
Nathan Guse
2012-11-20 18:14:48 -06:00
parent d2187424da
commit 2afb8b9df8
30 changed files with 518 additions and 325 deletions

View File

@@ -11,6 +11,9 @@ use Symfony\Component\DependencyInjection\ScopeInterface;
class phpbb_mock_container_builder implements ContainerInterface
{
protected $services = array();
protected $parameters = array();
/**
* Sets a service.
*
@@ -22,6 +25,7 @@ class phpbb_mock_container_builder implements ContainerInterface
*/
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
{
$this->services[$id] = $service;
}
/**
@@ -42,6 +46,12 @@ class phpbb_mock_container_builder implements ContainerInterface
*/
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
{
if ($this->has($id))
{
return $this->services[$id];
}
throw new Exception('Could not find service: ' . $id);
}
/**
@@ -55,6 +65,7 @@ class phpbb_mock_container_builder implements ContainerInterface
*/
public function has($id)
{
return isset($this->services[$id]);
}
/**
@@ -70,6 +81,12 @@ class phpbb_mock_container_builder implements ContainerInterface
*/
public function getParameter($name)
{
if ($this->hasParameter($name))
{
return $this->parameters[$name];
}
throw new Exception('Could not find parameter: ' . $name);
}
/**
@@ -83,6 +100,7 @@ class phpbb_mock_container_builder implements ContainerInterface
*/
public function hasParameter($name)
{
return isset($this->parameters[$name]);
}
/**
@@ -95,6 +113,7 @@ class phpbb_mock_container_builder implements ContainerInterface
*/
public function setParameter($name, $value)
{
$this->parameters[$name] = $value;
}
/**

View File

@@ -0,0 +1,69 @@
<?php
/**
*
* @package notifications
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Notifications service class
* @package notifications
*/
class phpbb_mock_notifications_notification_manager extends phpbb_notification_manager
{
public function set_var($name, $value)
{
$this->$name = $value;
}
// Extra dependencies for get_*_class functions
protected $auth = null;
protected $cache = null;
protected $config = null;
public function setDependencies($auth, $cache, $config)
{
$this->auth = $auth;
$this->cache = $cache;
$this->config = $config;
}
/**
* Helper to get the notifications item type class and set it up
*/
public function get_item_type_class($item_type, $data = array())
{
$item_type = 'phpbb_notification_type_' . $item_type;
$item = new $item_type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notifications_table, $this->user_notifications_table);
$item->set_notification_manager($this);
$item->set_initial_data($data);
return $item;
}
/**
* Helper to get the notifications method class and set it up
*/
public function get_method_class($method_name)
{
$method_name = 'phpbb_notification_method_' . $method_name;
$method = new $method_name($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notifications_table, $this->user_notifications_table);
$method->set_notification_manager($this);
return $method;
}
}