From b09293d5ff38633d506083cffc0a9dd2c98c15c4 Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Fri, 26 Jun 2015 01:02:04 +0200 Subject: [ticket/13961] Move back service_collections under original namespace PHPBB3-13961 --- phpBB/phpbb/di/ordered_service_collection.php | 121 +++++++++++++++++++++ phpBB/phpbb/di/service_collection.php | 79 ++++++++++++++ .../ordered_service_collection.php | 121 --------------------- .../di/service_collection/service_collection.php | 79 -------------- .../service_collection_iterator.php | 46 -------- phpBB/phpbb/di/service_collection_iterator.php | 46 ++++++++ 6 files changed, 246 insertions(+), 246 deletions(-) create mode 100644 phpBB/phpbb/di/ordered_service_collection.php create mode 100644 phpBB/phpbb/di/service_collection.php delete mode 100644 phpBB/phpbb/di/service_collection/ordered_service_collection.php delete mode 100644 phpBB/phpbb/di/service_collection/service_collection.php delete mode 100644 phpBB/phpbb/di/service_collection/service_collection_iterator.php create mode 100644 phpBB/phpbb/di/service_collection_iterator.php (limited to 'phpBB/phpbb/di') diff --git a/phpBB/phpbb/di/ordered_service_collection.php b/phpBB/phpbb/di/ordered_service_collection.php new file mode 100644 index 0000000000..46f397a004 --- /dev/null +++ b/phpBB/phpbb/di/ordered_service_collection.php @@ -0,0 +1,121 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\di; + +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * Collection of services in a specified order + */ +class ordered_service_collection extends service_collection +{ + /** + * @var bool + */ + protected $is_ordered; + + /** + * @var array + */ + protected $service_ids; + + /** + * Constructor + * + * @param ContainerInterface $container Container object + */ + public function __construct(ContainerInterface $container) + { + $this->is_ordered = false; + $this->service_ids = array(); + + parent::__construct($container); + } + + /** + * {@inheritdoc} + */ + public function getIterator() + { + if (!$this->is_ordered) + { + $this->sort_services(); + } + + return new service_collection_iterator($this); + } + + /** + * {@inheritdoc} + */ + public function offsetExists($index) + { + if (!$this->is_ordered) + { + $this->sort_services(); + } + + return parent::offsetExists($index); + } + + /** + * {@inheritdoc} + */ + public function offsetGet($index) + { + if (!$this->is_ordered) + { + $this->sort_services(); + } + + return parent::offsetGet($index); + } + + /** + * Adds a service ID to the collection + * + * @param string $service_id + * @param int $order + */ + public function add($service_id, $order = 0) + { + if ($this->is_ordered) + { + return; + } + + $order = (int) $order; + + $this->service_ids[$order][] = $service_id; + } + + protected function sort_services() + { + if ($this->is_ordered) + { + return; + } + + ksort($this->service_ids); + foreach ($this->service_ids as $service_order_group) + { + foreach ($service_order_group as $service_id) + { + $this->offsetSet($service_id, null); + } + } + + $this->is_ordered = true; + } +} diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php new file mode 100644 index 0000000000..82ca9bf679 --- /dev/null +++ b/phpBB/phpbb/di/service_collection.php @@ -0,0 +1,79 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\di; + +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** +* Collection of services to be configured at container compile time. +*/ +class service_collection extends \ArrayObject +{ + /** + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** + * Constructor + * + * @param ContainerInterface $container Container object + */ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + /** + * {@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); + } + + /** + * Add a service to the collection + * + * @param string $name The service name + * @return null + */ + public function add($name) + { + $this->offsetSet($name, null); + } +} diff --git a/phpBB/phpbb/di/service_collection/ordered_service_collection.php b/phpBB/phpbb/di/service_collection/ordered_service_collection.php deleted file mode 100644 index 8d56434504..0000000000 --- a/phpBB/phpbb/di/service_collection/ordered_service_collection.php +++ /dev/null @@ -1,121 +0,0 @@ - - * @license GNU General Public License, version 2 (GPL-2.0) - * - * For full copyright and license information, please see - * the docs/CREDITS.txt file. - * - */ - -namespace phpbb\di\service_collection; - -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Collection of services in a specified order - */ -class ordered_service_collection extends service_collection -{ - /** - * @var bool - */ - protected $is_ordered; - - /** - * @var array - */ - protected $service_ids; - - /** - * Constructor - * - * @param ContainerInterface $container Container object - */ - public function __construct(ContainerInterface $container) - { - $this->is_ordered = false; - $this->service_ids = array(); - - parent::__construct($container); - } - - /** - * {@inheritdoc} - */ - public function getIterator() - { - if (!$this->is_ordered) - { - $this->sort_services(); - } - - return new service_collection_iterator($this); - } - - /** - * {@inheritdoc} - */ - public function offsetExists($index) - { - if (!$this->is_ordered) - { - $this->sort_services(); - } - - return parent::offsetExists($index); - } - - /** - * {@inheritdoc} - */ - public function offsetGet($index) - { - if (!$this->is_ordered) - { - $this->sort_services(); - } - - return parent::offsetGet($index); - } - - /** - * Adds a service ID to the collection - * - * @param string $service_id - * @param int $order - */ - public function add($service_id, $order = 0) - { - if ($this->is_ordered) - { - return; - } - - $order = (int) $order; - - $this->service_ids[$order][] = $service_id; - } - - protected function sort_services() - { - if ($this->is_ordered) - { - return; - } - - ksort($this->service_ids); - foreach ($this->service_ids as $service_order_group) - { - foreach ($service_order_group as $service_id) - { - $this->offsetSet($service_id, null); - } - } - - $this->is_ordered = true; - } -} diff --git a/phpBB/phpbb/di/service_collection/service_collection.php b/phpBB/phpbb/di/service_collection/service_collection.php deleted file mode 100644 index 8085128fed..0000000000 --- a/phpBB/phpbb/di/service_collection/service_collection.php +++ /dev/null @@ -1,79 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\di\service_collection; - -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** -* Collection of services to be configured at container compile time. -*/ -class service_collection extends \ArrayObject -{ - /** - * @var \Symfony\Component\DependencyInjection\ContainerInterface - */ - protected $container; - - /** - * Constructor - * - * @param ContainerInterface $container Container object - */ - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - - /** - * {@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); - } - - /** - * Add a service to the collection - * - * @param string $name The service name - * @return null - */ - public function add($name) - { - $this->offsetSet($name, null); - } -} diff --git a/phpBB/phpbb/di/service_collection/service_collection_iterator.php b/phpBB/phpbb/di/service_collection/service_collection_iterator.php deleted file mode 100644 index 76e22b048e..0000000000 --- a/phpBB/phpbb/di/service_collection/service_collection_iterator.php +++ /dev/null @@ -1,46 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -namespace phpbb\di\service_collection; - -/** -* Iterator which loads the services when they are requested -*/ -class service_collection_iterator extends \ArrayIterator -{ - /** - * @var \phpbb\di\service_collection\service_collection - */ - protected $collection; - - /** - * Construct an ArrayIterator for service_collection - * - * @param \phpbb\di\service_collection\service_collection $collection The collection to iterate over - * @param int $flags Flags to control the behaviour of the ArrayObject object. - * @see ArrayObject::setFlags() - */ - public function __construct(service_collection $collection, $flags = 0) - { - parent::__construct($collection, $flags); - $this->collection = $collection; - } - - /** - * {@inheritdoc} - */ - public function current() - { - return $this->collection->offsetGet($this->key()); - } -} diff --git a/phpBB/phpbb/di/service_collection_iterator.php b/phpBB/phpbb/di/service_collection_iterator.php new file mode 100644 index 0000000000..0d031ab52d --- /dev/null +++ b/phpBB/phpbb/di/service_collection_iterator.php @@ -0,0 +1,46 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\di; + +/** +* Iterator which loads the services when they are requested +*/ +class service_collection_iterator extends \ArrayIterator +{ + /** + * @var \phpbb\di\service_collection + */ + protected $collection; + + /** + * Construct an ArrayIterator for service_collection + * + * @param \phpbb\di\service_collection $collection The collection to iterate over + * @param int $flags Flags to control the behaviour of the ArrayObject object. + * @see ArrayObject::setFlags() + */ + public function __construct(service_collection $collection, $flags = 0) + { + parent::__construct($collection, $flags); + $this->collection = $collection; + } + + /** + * {@inheritdoc} + */ + public function current() + { + return $this->collection->offsetGet($this->key()); + } +} -- cgit v1.2.1