當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Session::getCookiePath方法代碼示例

本文整理匯總了PHP中Magento\Customer\Model\Session::getCookiePath方法的典型用法代碼示例。如果您正苦於以下問題:PHP Session::getCookiePath方法的具體用法?PHP Session::getCookiePath怎麽用?PHP Session::getCookiePath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Customer\Model\Session的用法示例。


在下文中一共展示了Session::getCookiePath方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: execute

 /**
  * Renew persistent cookie
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if (!$this->_persistentData->canProcess($observer) || !$this->_persistentData->isEnabled() || !$this->_persistentSession->isPersistent()) {
         return;
     }
     /** @var $request \Magento\Framework\App\RequestInterface */
     $request = $observer->getEvent()->getRequest();
     if ($this->_customerSession->isLoggedIn() || $request->getFullActionName() == 'customer_account_logout') {
         $this->_sessionFactory->create()->renewPersistentCookie($this->_persistentData->getLifeTime(), $this->_customerSession->getCookiePath());
     }
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:17,代碼來源:RenewCookieObserver.php

示例2: execute

 /**
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute(Observer $observer)
 {
     /** @var $customer \Magento\Customer\Api\Data\CustomerInterface */
     $customer = $observer->getEvent()->getCustomer();
     // Check if customer is valid (remove persistent cookie for invalid customer)
     if (!$customer || !$customer->getId() || !$this->_persistentSession->isRememberMeChecked()) {
         $this->_sessionFactory->create()->removePersistentCookie();
         return;
     }
     $persistentLifeTime = $this->_persistentData->getLifeTime();
     // Delete persistent session, if persistent could not be applied
     if ($this->_persistentData->isEnabled() && $persistentLifeTime <= 0) {
         // Remove current customer persistent session
         $this->_sessionFactory->create()->deleteByCustomerId($customer->getId());
         return;
     }
     /** @var $sessionModel \Magento\Persistent\Model\Session */
     $sessionModel = $this->_persistentSession->getSession();
     // Check if session is wrong or not exists, so create new session
     if (!$sessionModel->getId() || $sessionModel->getCustomerId() != $customer->getId()) {
         /** @var \Magento\Persistent\Model\Session $sessionModel */
         $sessionModel = $this->_sessionFactory->create();
         $sessionModel->setLoadExpired()->loadByCustomerId($customer->getId());
         if (!$sessionModel->getId()) {
             /** @var \Magento\Persistent\Model\Session $sessionModel */
             $sessionModel = $this->_sessionFactory->create();
             $sessionModel->setCustomerId($customer->getId())->save();
         }
         $this->_persistentSession->setSession($sessionModel);
     }
     // Set new cookie
     if ($sessionModel->getId()) {
         $sessionModel->setPersistentCookie($persistentLifeTime, $this->_customerSession->getCookiePath());
     }
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:40,代碼來源:SynchronizePersistentOnLoginObserver.php

示例3: testSynchronizePersistentOnLogin

 /**
  * @covers \Magento\Persistent\Model\Observer\Session::synchronizePersistentOnLogin
  */
 public function testSynchronizePersistentOnLogin()
 {
     $event = new \Magento\Framework\Event();
     $observer = new \Magento\Framework\Event\Observer(array('event' => $event));
     /** @var \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerAccountService */
     $customerAccountService = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface');
     /** @var $customer \Magento\Customer\Service\V1\Data\Customer */
     $customer = $customerAccountService->getCustomer(1);
     $event->setData('customer', $customer);
     $this->_persistentSession->setRememberMeChecked(true);
     $this->_cookieMock->expects($this->once())->method('set')->with(\Magento\Persistent\Model\Session::COOKIE_NAME, $this->anything(), $this->anything(), $this->_customerSession->getCookiePath());
     $this->_model->synchronizePersistentOnLogin($observer);
     // check that persistent session has been stored for Customer
     /** @var \Magento\Persistent\Model\Session $sessionModel */
     $sessionModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Persistent\\Model\\Session');
     $sessionModel->loadByCustomerId(1);
     $this->assertEquals(1, $sessionModel->getCustomerId());
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:21,代碼來源:SessionTest.php


注:本文中的Magento\Customer\Model\Session::getCookiePath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。