Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BuiltinPlugin.php
Go to the documentation of this file.
1 <?php
7 
14 use Zend\Http\Header\HeaderInterface as HttpHeaderInterface;
15 use Magento\PageCache\Model\Cache\Type as CacheType;
16 
23 {
27  private $config;
28 
32  private $kernel;
33 
37  private $state;
38 
42  private $registry;
43 
50  public function __construct(Config $config, Kernel $kernel, AppState $state, Registry $registry)
51  {
52  $this->config = $config;
53  $this->kernel = $kernel;
54  $this->state = $state;
55  $this->registry = $registry;
56  }
57 
69  {
70  $usePlugin = $this->registry->registry('use_page_cache_plugin');
71 
72  if (!$usePlugin || !$this->config->isEnabled() || $this->config->getType() != Config::BUILT_IN) {
73  return $result;
74  }
75 
76  if ($this->state->getMode() == AppState::MODE_DEVELOPER) {
77  $cacheControlHeader = $response->getHeader('Cache-Control');
78 
79  if ($cacheControlHeader instanceof HttpHeaderInterface) {
80  $response->setHeader('X-Magento-Cache-Control', $cacheControlHeader->getFieldValue());
81  }
82 
83  $response->setHeader('X-Magento-Cache-Debug', 'MISS', true);
84  }
85 
86  $tagsHeader = $response->getHeader('X-Magento-Tags');
87  $tags = [];
88 
89  if ($tagsHeader) {
90  $tags = explode(',', $tagsHeader->getFieldValue());
91  $response->clearHeader('X-Magento-Tags');
92  }
93 
94  $tags = array_unique(array_merge($tags, [CacheType::CACHE_TAG]));
95  $response->setHeader('X-Magento-Tags', implode(',', $tags));
96  $this->kernel->process($response);
97 
98  return $result;
99  }
100 }
$response
Definition: 404.php:11
$config
Definition: fraud_order.php:17
__construct(Config $config, Kernel $kernel, AppState $state, Registry $registry)
$kernel
Definition: _bootstrap.php:17
afterRenderResult(ResultInterface $subject, ResultInterface $result, ResponseHttp $response)