MergePlugin.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\PageCache\Model\Layout;
  7. use Magento\Framework\View\EntitySpecificHandlesList;
  8. /**
  9. * Plugin for @see \Magento\Framework\View\Model\Layout\Merge
  10. */
  11. class MergePlugin
  12. {
  13. /**
  14. * @var EntitySpecificHandlesList
  15. */
  16. private $entitySpecificHandlesList;
  17. /**
  18. * Constructor
  19. *
  20. * @param EntitySpecificHandlesList $entitySpecificHandlesList
  21. */
  22. public function __construct(
  23. EntitySpecificHandlesList $entitySpecificHandlesList
  24. ) {
  25. $this->entitySpecificHandlesList = $entitySpecificHandlesList;
  26. }
  27. /**
  28. * Make sure that page specific handles (those which contain entity ID) do not have any declarations of ESI blocks
  29. *
  30. * ESI blocks cannot be declared for page specific handles, otherwise they will not be shared between pages
  31. *
  32. * @param \Magento\Framework\View\Model\Layout\Merge $subject
  33. * @param string $handle
  34. * @param string $updateXml
  35. * @return array|null
  36. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  37. */
  38. public function beforeValidateUpdate(\Magento\Framework\View\Model\Layout\Merge $subject, $handle, $updateXml)
  39. {
  40. if (in_array($handle, $this->entitySpecificHandlesList->getHandles())
  41. && (strpos($updateXml, 'ttl=') !== false)
  42. ) {
  43. throw new \LogicException(
  44. "Handle '{$handle}' must not contain blocks with 'ttl' attribute specified. "
  45. . "Otherwise, these blocks will be treated as ESI by Varnish, however will not be shared between pages "
  46. . "because handle '{$handle}' is not generic. Such blocks will not be rendered on the page"
  47. );
  48. }
  49. return null;
  50. }
  51. }