File tree Expand file tree Collapse file tree 2 files changed +17
-17
lines changed
Expand file tree Collapse file tree 2 files changed +17
-17
lines changed Original file line number Diff line number Diff line change 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 *
21- * See https://symfony.com/doc/current/book/internals.html#kernel-controller-event
22- *
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
26- *
2723 * @author Ryan Weaver <weaverryan@gmail.com>
2824 * @author Javier Eguiluz <javier.eguiluz@gmail.com>
2925 */
30- class ControllerListener
26+ class ControllerListener implements EventSubscriberInterface
3127{
3228 private $ twigExtension ;
3329
@@ -45,4 +41,14 @@ public function registerCurrentController(FilterControllerEvent $event)
4541 $ this ->twigExtension ->setController ($ event ->getController ());
4642 }
4743 }
44+
45+ /**
46+ * {@inheritdoc}
47+ */
48+ public static function getSubscribedEvents ()
49+ {
50+ return [
51+ KernelEvents::CONTROLLER => 'registerCurrentController ' ,
52+ ];
53+ }
4854}
Original file line number Diff line number Diff line change 11services :
2- code_explorer.twig.source_code_extension :
3- public : false
4- class : CodeExplorerBundle\Twig\SourceCodeExtension
5- tags :
6- - { name: twig.extension }
2+ _defaults : { public: false, autoconfigure: true }
73
8- code_explorer.controller_listener :
9- class : CodeExplorerBundle\EventListener\ControllerListener
10- arguments : ['@code_explorer.twig.source_code_extension']
11- tags :
12- - { name: kernel.event_listener, event: kernel.controller, method: registerCurrentController }
4+ CodeExplorerBundle\Twig\SourceCodeExtension : ~
5+
6+ CodeExplorerBundle\EventListener\ControllerListener : ['@CodeExplorerBundle\Twig\SourceCodeExtension']
You can’t perform that action at this time.
0 commit comments