1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-29 10:39:19 +02:00
php-phpbb/phpBB/phpbb/di/service_collection.php
Tristan Darricau bea9372efa [ticket/12575] Fix the tests
PHPBB3-12575
2014-06-14 01:45:21 +02:00

74 lines
1.3 KiB
PHP

<?php
/**
*
* 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.
*
*/
namespace phpbb\di;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Collection of services to be configured at container compile time.
*/
class service_collection extends \ArrayObject
{
/**
* Constructor
*
* @param ContainerInterface $container Container object
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* {@inheritdoc}
*/
public function getIterator()
{
return new service_collection_iterator($this->container, $this);
}
/**
* {@inheritdoc}
*/
public function offsetExists($index)
{
return parent::offsetExists($index);
}
/**
* {@inheritdoc}
*/
public function offsetGet($index)
{
if (($task = parent::offsetGet($index)) == null)
{
$task = $this->container->get($index);
$this->offsetSet($index, $task);
}
return $task;
}
/**
* Add a service to the collection
*
* @param string $name The service name
* @return null
*/
public function add($name)
{
$this->offsetSet($name, null);
}
}