Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Logout.php
Go to the documentation of this file.
1 <?php
8 
17 
22 {
26  protected $session;
27 
31  private $cookieMetadataFactory;
32 
36  private $cookieMetadataManager;
37 
42  public function __construct(
43  Context $context,
44  Session $customerSession
45  ) {
46  $this->session = $customerSession;
47  parent::__construct($context);
48  }
49 
56  private function getCookieManager()
57  {
58  if (!$this->cookieMetadataManager) {
59  $this->cookieMetadataManager = ObjectManager::getInstance()->get(PhpCookieManager::class);
60  }
61  return $this->cookieMetadataManager;
62  }
63 
70  private function getCookieMetadataFactory()
71  {
72  if (!$this->cookieMetadataFactory) {
73  $this->cookieMetadataFactory = ObjectManager::getInstance()->get(CookieMetadataFactory::class);
74  }
75  return $this->cookieMetadataFactory;
76  }
77 
83  public function execute()
84  {
85  $lastCustomerId = $this->session->getId();
86  $this->session->logout()->setBeforeAuthUrl($this->_redirect->getRefererUrl())
87  ->setLastCustomerId($lastCustomerId);
88  if ($this->getCookieManager()->getCookie('mage-cache-sessid')) {
89  $metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
90  $metadata->setPath('/');
91  $this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);
92  }
93 
95  $resultRedirect = $this->resultRedirectFactory->create();
96  $resultRedirect->setPath('*/*/logoutSuccess');
97  return $resultRedirect;
98  }
99 }
_redirect($path, $arguments=[])
Definition: Action.php:167
__construct(Context $context, Session $customerSession)
Definition: Logout.php:42