diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index bdba9ca4299a7..a1934f286695d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -4,6 +4,8 @@ CHANGELOG 2.3.0 ----- + * [BC BREAK] the `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass` was moved + to `Component\HttpKernel\DependencyInjection\RegisterListenersPass` * added ControllerNameParser::build() to converts a controller short notation (a:b:c) to a class::method notation * added possibility to run PHP built-in server in production environment * added possibility to load the serializer component in the service container diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index d96e187125280..085ad876df1e9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -15,7 +15,6 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass; -use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass; @@ -31,6 +30,7 @@ use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Bundle\Bundle; +use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass; /** * Bundle. @@ -56,7 +56,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new RoutingResolverPass()); $container->addCompilerPass(new ProfilerPass()); - $container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING); + $container->addCompilerPass(new RegisterListenersPass(), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new TemplatingPass()); $container->addCompilerPass(new AddConstraintValidatorsPass()); $container->addCompilerPass(new AddValidatorInitializersPass()); diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterKernelListenersPass.php b/src/Symfony/Component/HttpKernel/DependencyInjection/RegisterListenersPass.php similarity index 60% rename from src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterKernelListenersPass.php rename to src/Symfony/Component/HttpKernel/DependencyInjection/RegisterListenersPass.php index ad406eb6a3d90..ee00fbb6656bc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterKernelListenersPass.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/RegisterListenersPass.php @@ -9,22 +9,54 @@ * file that was distributed with this source code. */ -namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; +namespace Symfony\Component\HttpKernel\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -class RegisterKernelListenersPass implements CompilerPassInterface +/** + * Compiler pass to register tagged services for an event dispatcher. + */ +class RegisterListenersPass implements CompilerPassInterface { + /** + * @var string + */ + protected $dispatcherService; + + /** + * @var string + */ + protected $listenerTag; + + /** + * @var string + */ + protected $subscriberTag; + + /** + * Constructor. + * + * @param string $dispatcherService Service name of the event dispatcher in processed container + * @param string $listenerTag Tag name used for listener + * @param string $subscriberTag Tag name used for subscribers + */ + public function __construct($dispatcherService = 'event_dispatcher', $listenerTag = 'kernel.event_listener', $subscriberTag = 'kernel.event_subscriber') + { + $this->dispatcherService = $dispatcherService; + $this->listenerTag = $listenerTag; + $this->subscriberTag = $subscriberTag; + } + public function process(ContainerBuilder $container) { - if (!$container->hasDefinition('event_dispatcher')) { + if (!$container->hasDefinition($this->dispatcherService)) { return; } - $definition = $container->getDefinition('event_dispatcher'); + $definition = $container->getDefinition($this->dispatcherService); - foreach ($container->findTaggedServiceIds('kernel.event_listener') as $id => $events) { + foreach ($container->findTaggedServiceIds($this->listenerTag) as $id => $events) { foreach ($events as $event) { $priority = isset($event['priority']) ? $event['priority'] : 0; @@ -44,7 +76,7 @@ public function process(ContainerBuilder $container) } } - foreach ($container->findTaggedServiceIds('kernel.event_subscriber') as $id => $attributes) { + foreach ($container->findTaggedServiceIds($this->subscriberTag) as $id => $attributes) { // We must assume that the class value has been correctly filled, even if the service is created by a factory $class = $container->getDefinition($id)->getClass(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/RegisterKernelListenersPassTest.php b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterListenersPassTest.php similarity index 84% rename from src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/RegisterKernelListenersPassTest.php rename to src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterListenersPassTest.php index 670052fe1b3ad..d1e825a8241b2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/RegisterKernelListenersPassTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterListenersPassTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler; +namespace Symfony\Component\HttpKernel\Tests\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass; +use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass; -class RegisterKernelListenersPassTest extends \PHPUnit_Framework_TestCase +class RegisterListenersPassTest extends \PHPUnit_Framework_TestCase { /** * Tests that event subscribers not implementing EventSubscriberInterface @@ -49,7 +49,7 @@ public function testEventSubscriberWithoutInterface() ->method('getDefinition') ->will($this->returnValue($definition)); - $registerListenersPass = new RegisterKernelListenersPass(); + $registerListenersPass = new RegisterListenersPass(); $registerListenersPass->process($builder); } @@ -62,7 +62,7 @@ public function testValidEventSubscriber() $definition = $this->getMock('Symfony\Component\DependencyInjection\Definition'); $definition->expects($this->atLeastOnce()) ->method('getClass') - ->will($this->returnValue('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\SubscriberService')); + ->will($this->returnValue('Symfony\Component\HttpKernel\Tests\DependencyInjection\SubscriberService')); $builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); $builder->expects($this->any()) @@ -78,7 +78,7 @@ public function testValidEventSubscriber() ->method('getDefinition') ->will($this->returnValue($definition)); - $registerListenersPass = new RegisterKernelListenersPass(); + $registerListenersPass = new RegisterListenersPass(); $registerListenersPass->process($builder); } }