Skip to content

Commit 4e90e63

Browse files
committed
Use 3.3 DI features in CodeExplorerBundle
1 parent a99f756 commit 4e90e63

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/CodeExplorerBundle/EventListener/ControllerListener.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@
1212
namespace CodeExplorerBundle\EventListener;
1313

1414
use CodeExplorerBundle\Twig\SourceCodeExtension;
15+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1516
use 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
}
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
services:
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']

0 commit comments

Comments
 (0)