diff options
Diffstat (limited to 'phpBB/phpbb/di/service_collection.php')
-rw-r--r-- | phpBB/phpbb/di/service_collection.php | 77 |
1 files changed, 70 insertions, 7 deletions
diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index 65df9ab1d1..8e9175e204 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -1,9 +1,13 @@ <?php /** * -* @package phpBB3 -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -13,12 +17,20 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** * Collection of services to be configured at container compile time. -* -* @package phpBB3 */ class service_collection extends \ArrayObject { /** + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** + * @var array + */ + protected $service_classes; + + /** * Constructor * * @param ContainerInterface $container Container object @@ -26,6 +38,38 @@ class service_collection extends \ArrayObject public function __construct(ContainerInterface $container) { $this->container = $container; + $this->service_classes = array(); + } + + /** + * {@inheritdoc} + */ + public function getIterator() + { + return new service_collection_iterator($this); + } + + // Because of a PHP issue we have to redefine offsetExists + // (even with a call to the parent): + // https://bugs.php.net/bug.php?id=66834 + // https://bugs.php.net/bug.php?id=67067 + // But it triggers a sniffer issue that we have to skip + // @codingStandardsIgnoreStart + /** + * {@inheritdoc} + */ + public function offsetExists($index) + { + return parent::offsetExists($index); + } + // @codingStandardsIgnoreEnd + + /** + * {@inheritdoc} + */ + public function offsetGet($index) + { + return $this->container->get($index); } /** @@ -36,8 +80,27 @@ class service_collection extends \ArrayObject */ public function add($name) { - $task = $this->container->get($name); + $this->offsetSet($name, null); + } - $this->offsetSet($name, $task); + /** + * Add a service's class to the collection + * + * @param string $service_id + * @param string $class + */ + public function add_service_class($service_id, $class) + { + $this->service_classes[$service_id] = $class; + } + + /** + * Get services' classes + * + * @return array + */ + public function get_service_classes() + { + return $this->service_classes; } } |