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

DynamicSettingsListener.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\Event\PostSiteAccessMatchEvent;
10 use eZ\Publish\Core\MVC\Symfony\Event\ScopeChangeEvent;
11 use eZ\Publish\Core\MVC\Symfony\MVCEvents;
12 use Symfony\Component\DependencyInjection\ExpressionLanguage;
13 use Symfony\Component\DependencyInjection\ContainerInterface;
14 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15 use Symfony\Component\HttpKernel\HttpKernelInterface;
16
17 class DynamicSettingsListener implements EventSubscriberInterface
18 {
24 private $resettableServiceIds;
25
27 private $updatableServices;
28
30 private $expressionLanguage;
31
33 private $container;
34
35 public function __construct(array $resettableServiceIds, array $updatableServices, ExpressionLanguage $expressionLanguage = null)
36 {
37 $this->resettableServiceIds = $resettableServiceIds;
38 $this->updatableServices = $updatableServices;
39 $this->expressionLanguage = $expressionLanguage ?: new ExpressionLanguage();
40 }
41
42 public function setContainer(ContainerInterface $container)
43 {
44 $this->container = $container;
45 }
46
47 public static function getSubscribedEvents()
48 {
49 return [
50 MVCEvents::SITEACCESS => ['onSiteAccessMatch', 254],
51 MVCEvents::CONFIG_SCOPE_CHANGE => ['onConfigScopeChange', 90],
52 MVCEvents::CONFIG_SCOPE_RESTORE => ['onConfigScopeChange', 90],
53 ];
54 }
55
56 public function onSiteAccessMatch(PostSiteAccessMatchEvent $event)
57 {
58 if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
59 return;
60 }
61
62 $this->resetDynamicSettings();
63 }
64
65 public function onConfigScopeChange(ScopeChangeEvent $event)
66 {
67 $this->resetDynamicSettings();
68 }
69
74 private function resetDynamicSettings()
75 {
76 // Ensure to reset services that need to be.
77 foreach ($this->resettableServiceIds as $serviceId) {
78 if (!$this->container->initialized($serviceId)) {
79 continue;
80 }
81
82 $this->container->set($serviceId, null);
83 }
84
85 // Update services that can be updated.
86 foreach ($this->updatableServices as $serviceId => $methodCalls) {
87 if (!$this->container->initialized($serviceId)) {
88 continue;
89 }
90
91 $service = $this->container->get($serviceId);
92 foreach ($methodCalls as $callConfig) {
93 list($method, $expression) = $callConfig;
94 $argument = $this->expressionLanguage->evaluate($expression, ['container' => $this->container]);
95 call_user_func_array([$service, $method], [$argument]);
96 }
97 }
98 }
99 }
eZ\Bundle\EzPublishCoreBundle\EventListener\DynamicSettingsListener
Definition: DynamicSettingsListener.php:18
eZ\Bundle\EzPublishCoreBundle\EventListener\DynamicSettingsListener\$resettableServiceIds
$resettableServiceIds
Definition: DynamicSettingsListener.php:24
eZ\Bundle\EzPublishCoreBundle\EventListener\DynamicSettingsListener\$container
$container
Definition: DynamicSettingsListener.php:33
eZ\Bundle\EzPublishCoreBundle\EventListener\DynamicSettingsListener\$updatableServices
$updatableServices
Definition: DynamicSettingsListener.php:27
eZ\Bundle\EzPublishCoreBundle\EventListener\DynamicSettingsListener\setContainer
setContainer(ContainerInterface $container)
Definition: DynamicSettingsListener.php:42
eZ\Bundle\EzPublishCoreBundle\EventListener\DynamicSettingsListener\onConfigScopeChange
onConfigScopeChange(ScopeChangeEvent $event)
Definition: DynamicSettingsListener.php:65
eZ\Bundle\EzPublishCoreBundle\EventListener\DynamicSettingsListener\__construct
__construct(array $resettableServiceIds, array $updatableServices, ExpressionLanguage $expressionLanguage=null)
Definition: DynamicSettingsListener.php:35
eZ\Bundle\EzPublishCoreBundle\EventListener\DynamicSettingsListener\resetDynamicSettings
resetDynamicSettings()
Ensure that dynamic settings are correctly reset, so that services that rely on those are correctly u...
Definition: DynamicSettingsListener.php:74
eZ\Bundle\EzPublishCoreBundle\EventListener\DynamicSettingsListener\$expressionLanguage
$expressionLanguage
Definition: DynamicSettingsListener.php:30
eZ\Bundle\EzPublishCoreBundle\EventListener\DynamicSettingsListener\onSiteAccessMatch
onSiteAccessMatch(PostSiteAccessMatchEvent $event)
Definition: DynamicSettingsListener.php:56
eZ\Bundle\EzPublishCoreBundle\EventListener\DynamicSettingsListener\getSubscribedEvents
static getSubscribedEvents()
Definition: DynamicSettingsListener.php:47
eZ\Publish\Core\MVC\Symfony\Event\PostSiteAccessMatchEvent
This event is triggered after SiteAccess matching process and allows further control on it and the as...
Definition: PostSiteAccessMatchEvent.php:17
eZ\Publish\Core\MVC\Symfony\Event\PostSiteAccessMatchEvent\getRequestType
getRequestType()
Returns the request type the kernel is currently processing.
Definition: PostSiteAccessMatchEvent.php:63
eZ\Publish\Core\MVC\Symfony\Event\ScopeChangeEvent
This event is sent when configuration scope is changed (e.g.
Definition: ScopeChangeEvent.php:16
eZ\Publish\Core\MVC\Symfony\MVCEvents
Definition: MVCEvents.php:10
eZ\Publish\Core\MVC\Symfony\MVCEvents\CONFIG_SCOPE_RESTORE
const CONFIG_SCOPE_RESTORE
CONFIG_SCOPE_RESTORE event occurs when original configuration scope is restored.
Definition: MVCEvents.php:61
eZ\Publish\Core\MVC\Symfony\MVCEvents\SITEACCESS
const SITEACCESS
The SITEACCESS event occurs after the SiteAccess matching has occurred.
Definition: MVCEvents.php:17
eZ\Publish\Core\MVC\Symfony\MVCEvents\CONFIG_SCOPE_CHANGE
const CONFIG_SCOPE_CHANGE
CONFIG_SCOPE_CHANGE event occurs when configuration scope is changed (e.g.
Definition: MVCEvents.php:53
eZ\Bundle\EzPublishCoreBundle\EventListener
Definition: BackgroundIndexingTerminateListener.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.