Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

ViewControllerListener.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishCoreBundle\EventListener;
8
9 use eZ\Publish\Core\MVC\Symfony\View\Builder\ViewBuilderRegistry;
10 use eZ\Publish\Core\MVC\Symfony\View\Event\FilterViewBuilderParametersEvent;
11 use eZ\Publish\Core\MVC\Symfony\View\ViewEvents;
12 use Psr\Log\LoggerInterface;
13 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
14 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15 use Symfony\Component\HttpKernel\Controller\ControllerReference;
16 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
17 use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
18 use Symfony\Component\HttpKernel\KernelEvents;
19
20 class ViewControllerListener implements EventSubscriberInterface
21 {
23 private $controllerResolver;
24
26 private $logger;
27
29 private $viewBuilderRegistry;
30
32 private $eventDispatcher;
33
34 public function __construct(
35 ControllerResolverInterface $controllerResolver,
36 ViewBuilderRegistry $viewBuilderRegistry,
37 EventDispatcherInterface $eventDispatcher,
38 LoggerInterface $logger
39 ) {
40 $this->controllerResolver = $controllerResolver;
41 $this->viewBuilderRegistry = $viewBuilderRegistry;
42 $this->eventDispatcher = $eventDispatcher;
43 $this->logger = $logger;
44 }
45
46 public static function getSubscribedEvents()
47 {
48 return [KernelEvents::CONTROLLER => ['getController', 10]];
49 }
50
58 public function getController(FilterControllerEvent $event)
59 {
60 $request = $event->getRequest();
61
62 if (($viewBuilder = $this->viewBuilderRegistry->getFromRegistry($request->attributes->get('_controller'))) === null) {
63 return;
64 }
65
66 $parameterEvent = new FilterViewBuilderParametersEvent(clone $request);
67 $this->eventDispatcher->dispatch(ViewEvents::FILTER_BUILDER_PARAMETERS, $parameterEvent);
68 $view = $viewBuilder->buildView($parameterEvent->getParameters()->all());
69 $request->attributes->set('view', $view);
70
71 // View parameters are added as request attributes so that they are available as controller action parameters
72 $request->attributes->add($view->getParameters());
73
74 if (($controllerReference = $view->getControllerReference()) instanceof ControllerReference) {
75 $request->attributes->set('_controller', $controllerReference->controller);
76 $event->setController($this->controllerResolver->getController($request));
77 }
78 }
79 }
eZ\Bundle\EzPublishCoreBundle\EventListener\ViewControllerListener
Definition: ViewControllerListener.php:21
eZ\Bundle\EzPublishCoreBundle\EventListener\ViewControllerListener\__construct
__construct(ControllerResolverInterface $controllerResolver, ViewBuilderRegistry $viewBuilderRegistry, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger)
Definition: ViewControllerListener.php:34
eZ\Bundle\EzPublishCoreBundle\EventListener\ViewControllerListener\$viewBuilderRegistry
$viewBuilderRegistry
Definition: ViewControllerListener.php:29
eZ\Bundle\EzPublishCoreBundle\EventListener\ViewControllerListener\getController
getController(FilterControllerEvent $event)
Configures the View for eZ View controllers.
Definition: ViewControllerListener.php:58
eZ\Bundle\EzPublishCoreBundle\EventListener\ViewControllerListener\getSubscribedEvents
static getSubscribedEvents()
Definition: ViewControllerListener.php:46
eZ\Bundle\EzPublishCoreBundle\EventListener\ViewControllerListener\$logger
$logger
Definition: ViewControllerListener.php:26
eZ\Bundle\EzPublishCoreBundle\EventListener\ViewControllerListener\$eventDispatcher
$eventDispatcher
Definition: ViewControllerListener.php:32
eZ\Bundle\EzPublishCoreBundle\EventListener\ViewControllerListener\$controllerResolver
$controllerResolver
Definition: ViewControllerListener.php:23
eZ\Publish\Core\MVC\Symfony\View\Event\FilterViewBuilderParametersEvent
An event that collects the parameters the ViewBuilder will be provided to build View objects.
Definition: FilterViewBuilderParametersEvent.php:17
eZ\Publish\Core\MVC\Symfony\View\ViewEvents
Events constants of views.
Definition: ViewEvents.php:13
eZ\Publish\Core\MVC\Symfony\View\ViewEvents\FILTER_BUILDER_PARAMETERS
const FILTER_BUILDER_PARAMETERS
Dispatched before the ViewBuilder is called to collect the ViewBuilder parameters.
Definition: ViewEvents.php:21
eZ\Publish\Core\MVC\Symfony\View\Builder\ViewBuilderRegistry
A simple registry of ViewBuilders that uses the ViewBuilder's match() method to identify the builder.
Definition: ViewBuilderRegistry.php:13
eZ\Bundle\EzPublishCoreBundle\EventListener
Definition: BackgroundIndexingTerminateListener.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.