MockedDynamicPageCacheSubscriber.php in Permissions by Term 8.2
File
modules/permissions_by_entity/tests/modules/pbt_entity_test/src/EventSubscriber/MockedDynamicPageCacheSubscriber.php
View source
<?php
namespace Drupal\pbt_entity_test\EventSubscriber;
use Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
class MockedDynamicPageCacheSubscriber extends DynamicPageCacheSubscriber {
public function onRouteMatch(GetResponseEvent $event) {
$cached = $this->renderCache
->get($this->dynamicPageCacheRedirectRenderArray);
if ($cached) {
$response = $this
->renderArrayToResponse($cached);
$response->headers
->set(self::HEADER, 'HIT');
$event
->setResponse($response);
}
}
public function onResponse(FilterResponseEvent $event) {
$response = $event
->getResponse();
$response_as_render_array = $this
->responseToRenderArray($response);
$this->renderCache
->set($response_as_render_array, $this->dynamicPageCacheRedirectRenderArray);
$response->headers
->set(self::HEADER, 'MISS');
}
}