4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\DependencyInjection;
14 use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
15 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16 use Symfony\Component\DependencyInjection\ContainerBuilder;
17 use Symfony\Component\DependencyInjection\ContainerInterface;
18 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
19 use Symfony\Component\DependencyInjection\Reference;
22 * @author Alexander M. Turek <me@derrabus.de>
24 class ResettableServicePass implements CompilerPassInterface
28 public function __construct($tagName = 'kernel.reset')
30 $this->tagName = $tagName;
36 public function process(ContainerBuilder $container)
38 if (!$container->has('services_resetter')) {
42 $services = $methods = array();
44 foreach ($container->findTaggedServiceIds($this->tagName, true) as $id => $tags) {
45 $services[$id] = new Reference($id, ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE);
46 $attributes = $tags[0];
48 if (!isset($attributes['method'])) {
49 throw new RuntimeException(sprintf('Tag %s requires the "method" attribute to be set.', $this->tagName));
52 $methods[$id] = $attributes['method'];
55 if (empty($services)) {
56 $container->removeAlias('services_resetter');
57 $container->removeDefinition('services_resetter');
62 $container->findDefinition('services_resetter')
63 ->setArgument(0, new IteratorArgument($services))
64 ->setArgument(1, $methods);