Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Component\HttpKernel\DependencyInjection; Chris@14: Chris@14: use Symfony\Component\DependencyInjection\Argument\IteratorArgument; Chris@14: use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; Chris@14: use Symfony\Component\DependencyInjection\ContainerBuilder; Chris@14: use Symfony\Component\DependencyInjection\ContainerInterface; Chris@14: use Symfony\Component\DependencyInjection\Exception\RuntimeException; Chris@14: use Symfony\Component\DependencyInjection\Reference; Chris@14: Chris@14: /** Chris@14: * @author Alexander M. Turek Chris@14: */ Chris@14: class ResettableServicePass implements CompilerPassInterface Chris@14: { Chris@14: private $tagName; Chris@14: Chris@14: public function __construct($tagName = 'kernel.reset') Chris@14: { Chris@14: $this->tagName = $tagName; Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function process(ContainerBuilder $container) Chris@14: { Chris@14: if (!$container->has('services_resetter')) { Chris@14: return; Chris@14: } Chris@14: Chris@17: $services = $methods = []; Chris@14: Chris@14: foreach ($container->findTaggedServiceIds($this->tagName, true) as $id => $tags) { Chris@14: $services[$id] = new Reference($id, ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE); Chris@14: $attributes = $tags[0]; Chris@14: Chris@14: if (!isset($attributes['method'])) { Chris@14: throw new RuntimeException(sprintf('Tag %s requires the "method" attribute to be set.', $this->tagName)); Chris@14: } Chris@14: Chris@14: $methods[$id] = $attributes['method']; Chris@14: } Chris@14: Chris@14: if (empty($services)) { Chris@14: $container->removeAlias('services_resetter'); Chris@14: $container->removeDefinition('services_resetter'); Chris@14: Chris@14: return; Chris@14: } Chris@14: Chris@14: $container->findDefinition('services_resetter') Chris@14: ->setArgument(0, new IteratorArgument($services)) Chris@14: ->setArgument(1, $methods); Chris@14: } Chris@14: }