DepersonalizeChecker.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\PageCache\Model;
  7. /**
  8. * Checks if session should be depersonalized in Depersonalize plugin
  9. */
  10. class DepersonalizeChecker
  11. {
  12. /**
  13. * Request
  14. *
  15. * @var \Magento\Framework\App\RequestInterface
  16. */
  17. private $request;
  18. /**
  19. * Module manager
  20. *
  21. * @var \Magento\Framework\Module\Manager
  22. */
  23. private $moduleManager;
  24. /**
  25. * Cache config
  26. *
  27. * @var Config
  28. */
  29. private $cacheConfig;
  30. /**
  31. * @param \Magento\Framework\App\RequestInterface $request
  32. * @param \Magento\Framework\Module\Manager $moduleManager
  33. * @param Config $cacheConfig
  34. */
  35. public function __construct(
  36. \Magento\Framework\App\RequestInterface $request,
  37. \Magento\Framework\Module\Manager $moduleManager,
  38. Config $cacheConfig
  39. ) {
  40. $this->request = $request;
  41. $this->moduleManager = $moduleManager;
  42. $this->cacheConfig = $cacheConfig;
  43. }
  44. /**
  45. * Check if depersonalize or not
  46. *
  47. * @param \Magento\Framework\View\LayoutInterface $subject
  48. * @return bool
  49. * @api
  50. */
  51. public function checkIfDepersonalize(\Magento\Framework\View\LayoutInterface $subject)
  52. {
  53. return ($this->moduleManager->isEnabled('Magento_PageCache')
  54. && $this->cacheConfig->isEnabled()
  55. && !$this->request->isAjax()
  56. && ($this->request->isGet() || $this->request->isHead())
  57. && $subject->isCacheable());
  58. }
  59. }