Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RenewCookieObserver.php
Go to the documentation of this file.
1 <?php
7 
9 
11 
16 {
23 
29  protected $_persistentData = null;
30 
36  protected $_sessionFactory;
37 
43  protected $_customerSession;
44 
53  public function __construct(
54  \Magento\Persistent\Helper\Data $persistentData,
55  \Magento\Persistent\Helper\Session $persistentSession,
56  \Magento\Customer\Model\Session $customerSession,
57  \Magento\Persistent\Model\SessionFactory $sessionFactory
58  ) {
59  $this->_persistentData = $persistentData;
60  $this->_persistentSession = $persistentSession;
61  $this->_customerSession = $customerSession;
62  $this->_sessionFactory = $sessionFactory;
63  }
64 
71  public function execute(Observer $observer)
72  {
73  if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isEnabled()
74  || !$this->_persistentSession->isPersistent()
75  ) {
76  return;
77  }
78 
80  $request = $observer->getEvent()->getRequest();
81 
82  if ($this->_customerSession->isLoggedIn() || $request->getFullActionName() == 'customer_account_logout') {
83  $this->_sessionFactory->create()
84  ->renewPersistentCookie(
85  $this->_persistentData->getLifeTime(),
86  $this->_customerSession->getCookiePath()
87  );
88  }
89  }
90 }
$persistentSession
Definition: persistent.php:11