PersistentCustomerContext.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Persistent\Model\Plugin;
  8. /**
  9. * Plugin for Magento\Framework\App\Http\Context to create new page cache variation for persistent session.
  10. */
  11. class PersistentCustomerContext
  12. {
  13. /**
  14. * Persistent session.
  15. *
  16. * @var \Magento\Persistent\Helper\Session
  17. */
  18. private $persistentSession;
  19. /**
  20. * @param \Magento\Persistent\Helper\Session $persistentSession
  21. */
  22. public function __construct(
  23. \Magento\Persistent\Helper\Session $persistentSession
  24. ) {
  25. $this->persistentSession = $persistentSession;
  26. }
  27. /**
  28. * Sets appropriate header if customer session is persistent.
  29. *
  30. * @param \Magento\Framework\App\Http\Context $subject
  31. * @return mixed
  32. */
  33. public function beforeGetVaryString(\Magento\Framework\App\Http\Context $subject)
  34. {
  35. if ($this->persistentSession->isPersistent()) {
  36. $subject->setValue('PERSISTENT', 1, 0);
  37. }
  38. }
  39. }