8000 bug #9214 [FramworkBundle] Check event listener services are not abst… · symfony/symfony@e410b1f · GitHub
[go: up one dir, main page]

Skip to content

Commit e410b1f

Browse files
committed
bug #9214 [FramworkBundle] Check event listener services are not abstract (lyrixx)
This PR was merged into the 2.2 branch. Discussion ---------- [FramworkBundle] Check event listener services are not abstract | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 6744ead [FramworkBundle][HttpKernel] Check event listener services are not abstract
2 parents 6fce9d8 + 6744ead commit e410b1f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterKernelListenersPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public function process(ContainerBuilder $container)
3030
throw new \InvalidArgumentException(sprintf('The service "%s" must be public as event listeners are lazy-loaded.', $id));
3131
}
3232

33+
if ($def->isAbstract()) {
34+
throw new \InvalidArgumentException(sprintf('The service "%s" must not be abstract as event listeners are lazy-loaded.', $id));
35+
}
36+
3337
foreach ($events as $event) {
3438
$priority = isset($event['priority']) ? $event['priority'] : 0;
3539

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/RegisterKernelListenersPassTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ public function testPrivateEventSubscriber()
115115
$registerListenersPass = new RegisterKernelListenersPass();
116116
$registerListenersPass->process($container);
117117
}
118+
119+
/**
120+
* @expectedException \InvalidArgumentException
121+
* @expectedExceptionMessage The service "foo" must not be abstract as event listeners are lazy-loaded.
122+
*/
123+
public function testAbstractEventListener()
124+
{
125+
$container = new ContainerBuilder();
126+
$container->register('foo', 'stdClass')->setAbstract(true)->addTag('kernel.event_listener', array());
127+
$container->register('event_dispatcher', 'stdClass');
128+
129+
$registerListenersPass = new RegisterKernelListenersPass();
130+
$registerListenersPass->process($container);
131+
}
118132
}
119133

120134
class SubscriberService implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

0 commit comments

Comments
 (0)
0