CacheIdentifierPlugin.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\PageCache\Model\App;
  7. /**
  8. * Class CachePlugin
  9. * Should add design exceptions o identifier for built-in cache
  10. */
  11. class CacheIdentifierPlugin
  12. {
  13. /**
  14. * Constructor
  15. *
  16. * @param \Magento\Framework\View\DesignExceptions $designExceptions
  17. * @param \Magento\Framework\App\RequestInterface $request
  18. * @param \Magento\PageCache\Model\Config $config
  19. */
  20. public function __construct(
  21. \Magento\Framework\View\DesignExceptions $designExceptions,
  22. \Magento\Framework\App\RequestInterface $request,
  23. \Magento\PageCache\Model\Config $config
  24. ) {
  25. $this->designExceptions = $designExceptions;
  26. $this->request = $request;
  27. $this->config = $config;
  28. }
  29. /**
  30. * Adds a theme key to identifier for a built-in cache if user-agent theme rule is actual
  31. *
  32. * @param \Magento\Framework\App\PageCache\Identifier $identifier
  33. * @param string $result
  34. * @return string
  35. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  36. */
  37. public function afterGetValue(\Magento\Framework\App\PageCache\Identifier $identifier, $result)
  38. {
  39. if ($this->config->getType() == \Magento\PageCache\Model\Config::BUILT_IN && $this->config->isEnabled()) {
  40. $ruleDesignException = $this->designExceptions->getThemeByRequest($this->request);
  41. if ($ruleDesignException !== false) {
  42. return $ruleDesignException . $result;
  43. }
  44. }
  45. return $result;
  46. }
  47. }