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

BlockCacheResponseListener.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\CachableView;
10 use eZ\Publish\Core\MVC\Symfony\View\BlockView;
11 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
12 use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
13 use Symfony\Component\HttpKernel\KernelEvents;
14
18 class BlockCacheResponseListener implements EventSubscriberInterface
19 {
25 private $enableViewCache;
26
27 public function setEnableViewCache($enableViewCache)
28 {
29 $this->enableViewCache = $enableViewCache;
30 }
31
32 public static function getSubscribedEvents()
33 {
34 return [KernelEvents::RESPONSE => ['configureBlockCache', -10]];
35 }
36
37 public function configureBlockCache(FilterResponseEvent $event)
38 {
39 $view = $event->getRequest()->attributes->get('view');
40 if (!$view instanceof CachableView || !$view instanceof BlockView) {
41 return;
42 }
43
44 if (!$this->enableViewCache || !$view->isCacheEnabled()) {
45 return;
46 }
47
48 $response = $event->getResponse();
49 $response->setPublic();
50
51 $cacheSettings = $event->getRequest()->attributes->get('cacheSettings', []);
52
53 if (isset($cacheSettings['smax-age']) && is_int($cacheSettings['smax-age'])) {
54 $response->setSharedMaxAge((int) $cacheSettings['smax-age']);
55 }
56
57 if (isset($cacheSettings['max-age']) && is_int($cacheSettings['max-age'])) {
58 $response->setMaxAge((int) $cacheSettings['max-age']);
59 }
60 }
61 }
eZ\Bundle\EzPublishCoreBundle\EventListener\BlockCacheResponseListener
Configures the Response cache properties.
Definition: BlockCacheResponseListener.php:19
eZ\Bundle\EzPublishCoreBundle\EventListener\BlockCacheResponseListener\getSubscribedEvents
static getSubscribedEvents()
Definition: BlockCacheResponseListener.php:32
eZ\Bundle\EzPublishCoreBundle\EventListener\BlockCacheResponseListener\setEnableViewCache
setEnableViewCache($enableViewCache)
Definition: BlockCacheResponseListener.php:27
eZ\Bundle\EzPublishCoreBundle\EventListener\BlockCacheResponseListener\$enableViewCache
$enableViewCache
Definition: BlockCacheResponseListener.php:25
eZ\Bundle\EzPublishCoreBundle\EventListener\BlockCacheResponseListener\configureBlockCache
configureBlockCache(FilterResponseEvent $event)
Definition: BlockCacheResponseListener.php:37
eZ\Publish\Core\MVC\Symfony\View\BlockView
Definition: Publish/Core/MVC/Symfony/View/BlockView.php:12
eZ\Publish\Core\MVC\Symfony\View\CachableView
A view that can be cached over HTTP.
Definition: CachableView.php:15
eZ\Bundle\EzPublishCoreBundle\EventListener
Definition: BackgroundIndexingTerminateListener.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.