|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2025 Adobe |
| 4 | + * All rights reserved. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\PageCache\Model\App; |
| 9 | + |
| 10 | +use Magento\Store\Model\StoreManager; |
| 11 | + |
| 12 | +/** |
| 13 | + * Class CacheIdentifierForSavePlugin |
| 14 | + * |
| 15 | + * Should add design exceptions to identifier for built-in cache when saving |
| 16 | + */ |
| 17 | +class CacheIdentifierForSavePlugin |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var \Magento\Framework\View\DesignExceptions |
| 21 | + */ |
| 22 | + private $designExceptions; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var \Magento\Framework\App\RequestInterface |
| 26 | + */ |
| 27 | + private $request; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var \Magento\PageCache\Model\Config |
| 31 | + */ |
| 32 | + private $config; |
| 33 | + |
| 34 | + /** |
| 35 | + * @param \Magento\Framework\View\DesignExceptions $designExceptions |
| 36 | + * @param \Magento\Framework\App\RequestInterface $request |
| 37 | + * @param \Magento\PageCache\Model\Config $config |
| 38 | + */ |
| 39 | + public function __construct( |
| 40 | + \Magento\Framework\View\DesignExceptions $designExceptions, |
| 41 | + \Magento\Framework\App\RequestInterface $request, |
| 42 | + \Magento\PageCache\Model\Config $config |
| 43 | + ) { |
| 44 | + $this->designExceptions = $designExceptions; |
| 45 | + $this->request = $request; |
| 46 | + $this->config = $config; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Adds a theme key to identifier for a built-in cache if user-agent theme rule is actual |
| 51 | + * |
| 52 | + * @param \Magento\PageCache\Model\App\Request\Http\IdentifierForSave $identifier |
| 53 | + * @param string $result |
| 54 | + * @return string |
| 55 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 56 | + */ |
| 57 | + public function afterGetValue(\Magento\PageCache\Model\App\Request\Http\IdentifierForSave $identifier, $result) |
| 58 | + { |
| 59 | + if ($this->config->getType() === \Magento\PageCache\Model\Config::BUILT_IN && $this->config->isEnabled()) { |
| 60 | + $identifierPrefix = ''; |
| 61 | + |
| 62 | + $ruleDesignException = $this->designExceptions->getThemeByRequest($this->request); |
| 63 | + if ($ruleDesignException !== false) { |
| 64 | + $identifierPrefix .= 'DESIGN' . '=' . $ruleDesignException . '|'; |
| 65 | + } |
| 66 | + |
| 67 | + if ($runType = $this->request->getServerValue(StoreManager::PARAM_RUN_TYPE)) { |
| 68 | + $identifierPrefix .= StoreManager::PARAM_RUN_TYPE . '=' . $runType . '|'; |
| 69 | + } |
| 70 | + |
| 71 | + if ($runCode = $this->request->getServerValue(StoreManager::PARAM_RUN_CODE)) { |
| 72 | + $identifierPrefix .= StoreManager::PARAM_RUN_CODE . '=' . $runCode . '|'; |
| 73 | + } |
| 74 | + |
| 75 | + return $identifierPrefix . $result; |
| 76 | + } |
| 77 | + return $result; |
| 78 | + } |
| 79 | +} |
0 commit comments