Skip to content

Instantly share code, notes, and snippets.

@vrann
Created July 7, 2016 21:35
Show Gist options
  • Save vrann/82d80dab43f1f772cc4b0eae9568891c to your computer and use it in GitHub Desktop.
Save vrann/82d80dab43f1f772cc4b0eae9568891c to your computer and use it in GitHub Desktop.
Plugins.patch
Index: app/code/Magento/Cms/Controller/Index/Index.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/code/Magento/Cms/Controller/Index/Index.php (revision 151726ac76897cbf6437b9005fabda3305a5ea08)
+++ app/code/Magento/Cms/Controller/Index/Index.php (revision )
@@ -34,6 +34,7 @@
*/
public function execute($coreRoute = null)
{
+ throw new \Exception();
$pageId = $this->_objectManager->get(
'Magento\Framework\App\Config\ScopeConfigInterface'
)->getValue(
Index: var/generation/Magento/Framework/App/FrontController/Interceptor.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- var/generation/Magento/Framework/App/FrontController/Interceptor.php (revision )
+++ var/generation/Magento/Framework/App/FrontController/Interceptor.php (revision )
@@ -0,0 +1,60 @@
+<?php
+namespace Magento\Framework\App\FrontController;
+
+/**
+ * Interceptor class for @see \Magento\Framework\App\FrontController
+ */
+class Interceptor extends \Magento\Framework\App\FrontController implements \Magento\Framework\Interception\InterceptorInterface
+{
+ use \Magento\Framework\Interception\Interceptor;
+ use \Magento\PageCache\Model\App\FrontController\BuiltinPluginTrait;
+ use \Magento\PageCache\Model\App\FrontController\BuiltinPluginTrait;
+
+ /**
+ * Constructor
+ *
+ * @param \Magento\PageCache\Model\Config $config
+ * @param \Magento\Framework\App\PageCache\Version $version
+ * @param \Magento\Framework\App\PageCache\Kernel $kernel
+ * @param \Magento\Framework\App\State $state
+ */
+ public function __construct(
+ \Magento\Framework\App\RouterList $routerList, \Magento\Framework\App\Response\Http $response,
+ \Magento\PageCache\Model\Config $config,
+ \Magento\Framework\App\PageCache\Version $version,
+ \Magento\Framework\App\PageCache\Kernel $kernel,
+ \Magento\Framework\App\State $state
+ ) {
+ $this->config = $config;
+ $this->version = $version;
+ $this->kernel = $kernel;
+ $this->state = $state;
+ $this->___init();
+ parent::__construct($routerList, $response);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function dispatch(\Magento\Framework\App\RequestInterface $request)
+ {
+ $pluginInfo = $this->pluginList->getNext($this->subjectType, 'dispatch');
+ if (!$pluginInfo) {
+ return parent::dispatch($request);
+ } else {
+ $method = 'dispatch';
+ $capMethod = ucfirst($method);
+ $result = null;
+ // Call 'around' listener
+ $chain = $this->chain;
+ $type = $this->subjectType;
+ $subject = $this;
+ $code = $pluginInfo[\Magento\Framework\Interception\DefinitionInterface::LISTENER_AROUND];
+ $next = function () use ($chain, $type, $method, $subject, $code) {
+ return $chain->invokeNext($type, $method, $subject, func_get_args(), $code);
+ };
+ return $this->aroundDispatchBuitin($this, $next, $request);
+ //return $this->___callPlugins('dispatch', func_get_args(), $pluginInfo);
+ }
+ }
+}
Index: app/code/Magento/PageCache/Model/App/FrontController/BuiltinPluginTrait.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/code/Magento/PageCache/Model/App/FrontController/BuiltinPluginTrait.php (revision )
+++ app/code/Magento/PageCache/Model/App/FrontController/BuiltinPluginTrait.php (revision )
@@ -0,0 +1,97 @@
+<?php
+/**
+ * Copyright © 2016 Magento. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\PageCache\Model\App\FrontController;
+
+use Magento\Framework\App\Response\Http as ResponseHttp;
+
+/**
+ * Plugin for processing builtin cache
+ */
+trait BuiltinPluginTrait
+{
+ /**
+ * @var \Magento\Framework\App\Config\ScopeConfigInterface
+ */
+ protected $config;
+
+ /**
+ * @var \Magento\Framework\App\PageCache\Version
+ */
+ protected $version;
+
+ /**
+ * @var \Magento\Framework\App\PageCache\Kernel
+ */
+ protected $kernel;
+
+ /**
+ * @var \Magento\Framework\App\State
+ */
+ protected $state;
+
+
+
+ /**
+ * @param \Magento\Framework\App\FrontControllerInterface $subject
+ * @param callable $proceed
+ * @param \Magento\Framework\App\RequestInterface $request
+ * @return \Magento\Framework\Controller\ResultInterface|\Magento\Framework\App\Response\Http
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
+ public function aroundDispatch(
+ \Magento\Framework\App\FrontControllerInterface $subject,
+ \Closure $proceed,
+ \Magento\Framework\App\RequestInterface $request
+ ) {
+ if (!$this->config->isEnabled() || $this->config->getType() != \Magento\PageCache\Model\Config::BUILT_IN) {
+ return $proceed($request);
+ }
+ $this->version->process();
+ $result = $this->kernel->load();
+ if ($result === false) {
+ $result = $proceed($request);
+ if ($result instanceof ResponseHttp) {
+ $this->addDebugHeaders($result);
+ $this->kernel->process($result);
+ }
+ } else {
+ $this->addDebugHeader($result, 'X-Magento-Cache-Debug', 'HIT', true);
+ }
+ return $result;
+ }
+
+ /**
+ * Set cache control
+ *
+ * @param ResponseHttp $result
+ * @return ResponseHttp
+ */
+ protected function addDebugHeaders(ResponseHttp $result)
+ {
+ $cacheControlHeader = $result->getHeader('Cache-Control');
+ if ($cacheControlHeader instanceof \Zend\Http\Header\HeaderInterface) {
+ $this->addDebugHeader($result, 'X-Magento-Cache-Control', $cacheControlHeader->getFieldValue());
+ }
+ $this->addDebugHeader($result, 'X-Magento-Cache-Debug', 'MISS', true);
+ return $result;
+ }
+
+ /**
+ * Add additional header for debug purpose
+ *
+ * @param ResponseHttp $response
+ * @param string $name
+ * @param string $value
+ * @param bool $replace
+ * @return void
+ */
+ protected function addDebugHeader(ResponseHttp $response, $name, $value, $replace = false)
+ {
+ if ($this->state->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
+ $response->setHeader($name, $value, $replace);
+ }
+ }
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment