1212namespace CodeExplorerBundle \EventListener ;
1313
1414use CodeExplorerBundle \Twig \SourceCodeExtension ;
15+ use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
1516use Symfony \Component \HttpKernel \Event \FilterControllerEvent ;
17+ use Symfony \Component \HttpKernel \KernelEvents ;
1618
1719/**
1820 * Defines the method that 'listens' to the 'kernel.controller' event, which is
1921 * triggered whenever a controller is executed in the application.
2022 *
2123 * See https://symfony.com/doc/current/book/internals.html#kernel-controller-event
2224 *
23- * Tip: listeners are common in Symfony applications, but this particular listener
24- * is too advanced and too specific for the demo application needs. For more common
25- * examples see https://symfony.com/doc/current/cookbook/service_container/event_listener .html
25+ * Tip: listeners and subscribers are common in Symfony applications, but this particular
26+ * one is too advanced and too specific for the demo application needs.
27+ * For more common examples see https://symfony.com/doc/current/event_dispatcher .html
2628 *
2729 * @author Ryan Weaver <[email protected] > 2830 * @author Javier Eguiluz <[email protected] > 2931 */
30- class ControllerListener
32+ class ControllerListener implements EventSubscriberInterface
3133{
3234 private $ twigExtension ;
3335
@@ -45,4 +47,14 @@ public function registerCurrentController(FilterControllerEvent $event)
4547 $ this ->twigExtension ->setController ($ event ->getController ());
4648 }
4749 }
50+
51+ /**
52+ * {@inheritdoc}
53+ */
54+ public static function getSubscribedEvents ()
55+ {
56+ return [
57+ KernelEvents::CONTROLLER => 'registerCurrentController ' ,
58+ ];
59+ }
4860}
0 commit comments