当前位置: 首页>>代码示例>>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;未经允许,请勿转载。