Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/CodeExplorerBundle/EventListener/ControllerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,18 @@
namespace CodeExplorerBundle\EventListener;

use CodeExplorerBundle\Twig\SourceCodeExtension;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* Defines the method that 'listens' to the 'kernel.controller' event, which is
* triggered whenever a controller is executed in the application.
*
* See https://symfony.com/doc/current/book/internals.html#kernel-controller-event
*
* Tip: listeners are common in Symfony applications, but this particular listener
* is too advanced and too specific for the demo application needs. For more common
* examples see https://symfony.com/doc/current/cookbook/service_container/event_listener.html
*
* @author Ryan Weaver <[email protected]>
* @author Javier Eguiluz <[email protected]>
*/
class ControllerListener
class ControllerListener implements EventSubscriberInterface
{
private $twigExtension;

Expand All @@ -45,4 +41,14 @@ public function registerCurrentController(FilterControllerEvent $event)
$this->twigExtension->setController($event->getController());
}
}

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => 'registerCurrentController',
];
}
}
14 changes: 4 additions & 10 deletions src/CodeExplorerBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
services:
code_explorer.twig.source_code_extension:
public: false
class: CodeExplorerBundle\Twig\SourceCodeExtension
tags:
- { name: twig.extension }
_defaults: { public: false, autoconfigure: true }

code_explorer.controller_listener:
class: CodeExplorerBundle\EventListener\ControllerListener
arguments: ['@code_explorer.twig.source_code_extension']
tags:
- { name: kernel.event_listener, event: kernel.controller, method: registerCurrentController }
CodeExplorerBundle\Twig\SourceCodeExtension: ~

CodeExplorerBundle\EventListener\ControllerListener: ['@CodeExplorerBundle\Twig\SourceCodeExtension']