Skip to content

Commit d05d2ee

Browse files
committed
feature #576 Use 3.3 DI features in CodeExplorerBundle (ogizanagi)
This PR was merged into the master branch. Discussion ---------- Use 3.3 DI features in CodeExplorerBundle Since 3.3, [listeners do not have to be public anymore](https://github.com/symfony/symfony/pull/20953/files#diff-8604f72b4ae78c6c364c1af8c1dee17cL63). I also believe declaring services private by default by adding `_defaults: { public: false }` on top will become a best practice, so I think we should use it in the CodeExplorerBundle. Actually, we could also use classnamed services, autoconfigure and autowiring, but at least for the last one, I think we should keep a place in this application where services are declared entirely manually (autoconfigure is debatable this way too, that's true). WDYT? Commits ------- c391498 Use 3.3 DI features in CodeExplorerBundle
2 parents c63ad95 + c391498 commit d05d2ee

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/CodeExplorerBundle/EventListener/ControllerListener.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,18 @@
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
*
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 <[email protected]>
2824
* @author Javier Eguiluz <[email protected]>
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
}
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)