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 
9 
14 {
18  protected $config;
19 
23  protected $version;
24 
28  protected $kernel;
29 
33  protected $state;
34 
43  public function __construct(
44  \Magento\PageCache\Model\Config $config,
45  \Magento\Framework\App\PageCache\Version $version,
46  \Magento\Framework\App\PageCache\Kernel $kernel,
47  \Magento\Framework\App\State $state
48  ) {
49  $this->config = $config;
50  $this->version = $version;
51  $this->kernel = $kernel;
52  $this->state = $state;
53  }
54 
62  public function aroundDispatch(
63  \Magento\Framework\App\FrontControllerInterface $subject,
64  \Closure $proceed,
65  \Magento\Framework\App\RequestInterface $request
66  ) {
67  $this->version->process();
68  if (!$this->config->isEnabled() || $this->config->getType() != \Magento\PageCache\Model\Config::BUILT_IN) {
69  return $proceed($request);
70  }
71  $result = $this->kernel->load();
72  if ($result === false) {
73  $result = $proceed($request);
74  if ($result instanceof ResponseHttp) {
75  $this->addDebugHeaders($result);
76  $this->kernel->process($result);
77  }
78  } else {
79  $this->addDebugHeader($result, 'X-Magento-Cache-Debug', 'HIT', true);
80  }
81  return $result;
82  }
83 
90  protected function addDebugHeaders(ResponseHttp $result)
91  {
92  $cacheControlHeader = $result->getHeader('Cache-Control');
93  if ($cacheControlHeader instanceof \Zend\Http\Header\HeaderInterface) {
94  $this->addDebugHeader($result, 'X-Magento-Cache-Control', $cacheControlHeader->getFieldValue());
95  }
96  $this->addDebugHeader($result, 'X-Magento-Cache-Debug', 'MISS', true);
97  return $result;
98  }
99 
109  protected function addDebugHeader(ResponseHttp $response, $name, $value, $replace = false)
110  {
111  if ($this->state->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
112  $response->setHeader($name, $value, $replace);
113  }
114  }
115 }
$response
Definition: 404.php:11
__construct(\Magento\PageCache\Model\Config $config, \Magento\Framework\App\PageCache\Version $version, \Magento\Framework\App\PageCache\Kernel $kernel, \Magento\Framework\App\State $state)
addDebugHeader(ResponseHttp $response, $name, $value, $replace=false)
aroundDispatch(\Magento\Framework\App\FrontControllerInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14