当前位置: 首页>>代码示例>>PHP>>正文


PHP Session\SessionManagerInterface类代码示例

本文整理汇总了PHP中Magento\Framework\Session\SessionManagerInterface的典型用法代码示例。如果您正苦于以下问题:PHP SessionManagerInterface类的具体用法?PHP SessionManagerInterface怎么用?PHP SessionManagerInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SessionManagerInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * Validate session
  *
  * @param SessionManagerInterface $session
  * @return void
  * @throws SessionException
  */
 public function validate(SessionManagerInterface $session)
 {
     if (!isset($_SESSION[self::VALIDATOR_KEY])) {
         $_SESSION[self::VALIDATOR_KEY] = $this->_getSessionEnvironment();
     } else {
         try {
             $this->_validate();
         } catch (SessionException $e) {
             $session->destroy(['clear_storage' => false]);
             // throw core session exception
             throw $e;
         }
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:21,代码来源:Validator.php

示例2: getConfig

 /**
  * Retrieve assoc array of checkout configuration
  *
  * @return array
  */
 public function getConfig()
 {
     $vaultPayments = [];
     $customerId = $this->session->getCustomerId();
     if (!$customerId) {
         return $vaultPayments;
     }
     $storeId = $this->storeManager->getStore()->getId();
     if (!$this->vaultPayment->isActive($storeId)) {
         return $vaultPayments;
     }
     $vaultProviderCode = $this->vaultPayment->getProviderCode($storeId);
     $componentProvider = $this->getComponentProvider($vaultProviderCode);
     if (null === $componentProvider) {
         return $vaultPayments;
     }
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::CUSTOMER_ID)->setValue($customerId)->create();
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::IS_VISIBLE)->setValue(1)->create();
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::PAYMENT_METHOD_CODE)->setValue($vaultProviderCode)->create();
     $searchCriteria = $this->searchCriteriaBuilder->addFilters($filters)->create();
     foreach ($this->paymentTokenRepository->getList($searchCriteria)->getItems() as $index => $token) {
         $component = $componentProvider->getComponentForToken($token);
         $vaultPayments[VaultPaymentInterface::CODE . '_item_' . $index] = ['config' => $component->getConfig(), 'component' => $component->getName()];
     }
     return ['payment' => [VaultPaymentInterface::CODE => $vaultPayments]];
 }
开发者ID:uibar,项目名称:lavinia2,代码行数:31,代码来源:TokensConfigProvider.php

示例3: aroundExecute

 /**
  * @param \Magento\Customer\Controller\Ajax\Login $subject
  * @param \Closure $proceed
  * @return $this
  * @throws \Zend_Json_Exception
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function aroundExecute(\Magento\Customer\Controller\Ajax\Login $subject, \Closure $proceed)
 {
     $captchaFormIdField = 'captcha_form_id';
     $captchaInputName = 'captcha_string';
     /** @var \Magento\Framework\App\RequestInterface $request */
     $request = $subject->getRequest();
     $loginParams = [];
     $content = $request->getContent();
     if ($content) {
         $loginParams = \Zend_Json::decode($content);
     }
     $username = isset($loginParams['username']) ? $loginParams['username'] : null;
     $captchaString = isset($loginParams[$captchaInputName]) ? $loginParams[$captchaInputName] : null;
     $loginFormId = isset($loginParams[$captchaFormIdField]) ? $loginParams[$captchaFormIdField] : null;
     foreach ($this->formIds as $formId) {
         $captchaModel = $this->helper->getCaptcha($formId);
         if ($captchaModel->isRequired($username) && !in_array($loginFormId, $this->formIds)) {
             $resultJson = $this->resultJsonFactory->create();
             return $resultJson->setData(['errors' => true, 'message' => __('Provided form does not exist')]);
         }
         if ($formId == $loginFormId) {
             $captchaModel->logAttempt($username);
             if (!$captchaModel->isCorrect($captchaString)) {
                 $this->sessionManager->setUsername($username);
                 /** @var \Magento\Framework\Controller\Result\Json $resultJson */
                 $resultJson = $this->resultJsonFactory->create();
                 return $resultJson->setData(['errors' => true, 'message' => __('Incorrect CAPTCHA')]);
             }
         }
     }
     return $proceed();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:40,代码来源:AjaxLogin.php

示例4: aroundDispatch

 /**
  * @param \Magento\Framework\App\Action\Action $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  * @return mixed
  */
 public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     $defaultStore = $this->storeManager->getWebsite()->getDefaultStore();
     $this->httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_CURRENCY, $this->session->getCurrencyCode(), $defaultStore->getDefaultCurrency()->getCode());
     $this->httpContext->setValue(\Magento\Core\Helper\Data::CONTEXT_STORE, $this->httpRequest->getParam('___store', $defaultStore->getStoreCodeFromCookie()), $this->storeManager->getWebsite()->getDefaultStore()->getCode());
     return $proceed($request);
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:13,代码来源:Context.php

示例5: aroundDispatch

 /**
  * @param \Magento\Framework\App\ActionInterface $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  * @return mixed
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundDispatch(\Magento\Framework\App\ActionInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     /** @var \Magento\Store\Model\Store $defaultStore */
     $defaultStore = $this->storeManager->getWebsite()->getDefaultStore();
     $requestedStoreCode = $this->httpRequest->getParam(StoreResolverInterface::PARAM_NAME, $this->storeCookieManager->getStoreCodeFromCookie());
     /** @var \Magento\Store\Model\Store $currentStore */
     $currentStore = $requestedStoreCode ? $this->storeManager->getStore($requestedStoreCode) : $defaultStore;
     $this->httpContext->setValue(StoreManagerInterface::CONTEXT_STORE, $currentStore->getCode(), $this->storeManager->getDefaultStoreView()->getCode());
     $this->httpContext->setValue(HttpContext::CONTEXT_CURRENCY, $this->session->getCurrencyCode() ?: $currentStore->getDefaultCurrencyCode(), $defaultStore->getDefaultCurrencyCode());
     return $proceed($request);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:18,代码来源:Context.php

示例6: getConfig

 /**
  * Retrieve assoc array of checkout configuration
  *
  * @return array
  */
 public function getConfig()
 {
     $availableMethods = [];
     $vaultPayments = $this->getVaultPaymentMethodList();
     $customerId = $this->session->getCustomerId();
     $storeId = $this->storeManager->getStore()->getId();
     foreach ($vaultPayments as $method) {
         $availableMethods[$method->getCode()] = ['is_enabled' => $customerId !== null && $method->isActive($storeId)];
     }
     return [self::$vaultCode => $availableMethods];
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:16,代码来源:VaultConfigProvider.php

示例7: _prepareForm

 /**
  * Prepare rating edit form
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $this->setForm($form);
     $fieldset = $form->addFieldset('rating_form', array('legend' => __('Rating Title')));
     $fieldset->addField('rating_code', 'text', array('name' => 'rating_code', 'label' => __('Default Value'), 'class' => 'required-entry', 'required' => true));
     foreach ($this->_systemStore->getStoreCollection() as $store) {
         $fieldset->addField('rating_code_' . $store->getId(), 'text', array('label' => $store->getName(), 'name' => 'rating_codes[' . $store->getId() . ']'));
     }
     if ($this->_session->getRatingData()) {
         $form->setValues($this->_session->getRatingData());
         $data = $this->_session->getRatingData();
         if (isset($data['rating_codes'])) {
             $this->_setRatingCodes($data['rating_codes']);
         }
         $this->_session->setRatingData(null);
     } elseif ($this->_coreRegistry->registry('rating_data')) {
         $form->setValues($this->_coreRegistry->registry('rating_data')->getData());
         if ($this->_coreRegistry->registry('rating_data')->getRatingCodes()) {
             $this->_setRatingCodes($this->_coreRegistry->registry('rating_data')->getRatingCodes());
         }
     }
     if ($this->_coreRegistry->registry('rating_data')) {
         $collection = $this->_optionFactory->create()->getResourceCollection()->addRatingFilter($this->_coreRegistry->registry('rating_data')->getId())->load();
         $i = 1;
         foreach ($collection->getItems() as $item) {
             $fieldset->addField('option_code_' . $item->getId(), 'hidden', array('required' => true, 'name' => 'option_title[' . $item->getId() . ']', 'value' => $item->getCode() ? $item->getCode() : $i));
             $i++;
         }
     } else {
         for ($i = 1; $i <= 5; $i++) {
             $fieldset->addField('option_code_' . $i, 'hidden', array('required' => true, 'name' => 'option_title[add_' . $i . ']', 'value' => $i));
         }
     }
     $fieldset = $form->addFieldset('visibility_form', array('legend' => __('Rating Visibility')));
     if (!$this->_storeManager->isSingleStoreMode()) {
         $field = $fieldset->addField('stores', 'multiselect', array('label' => __('Visible In'), 'name' => 'stores[]', 'values' => $this->_systemStore->getStoreValuesForForm()));
         $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element');
         $field->setRenderer($renderer);
         if ($this->_coreRegistry->registry('rating_data')) {
             $form->getElement('stores')->setValue($this->_coreRegistry->registry('rating_data')->getStores());
         }
     }
     $fieldset->addField('is_active', 'checkbox', array('label' => __('Is Active'), 'name' => 'is_active', 'value' => 1));
     $fieldset->addField('position', 'text', array('label' => __('Sort Order'), 'name' => 'position'));
     if ($this->_coreRegistry->registry('rating_data')) {
         $form->getElement('position')->setValue($this->_coreRegistry->registry('rating_data')->getPosition());
         $form->getElement('is_active')->setIsChecked($this->_coreRegistry->registry('rating_data')->getIsActive());
     }
     return parent::_prepareForm();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:57,代码来源:Form.php

示例8: afterGenerateXml

 /**
  * After generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @param \Magento\Framework\View\LayoutInterface $result
  * @return \Magento\Framework\View\LayoutInterface
  */
 public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
 {
     if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
         $this->visitor->setSkipRequestLogging(true);
         $this->visitor->unsetData();
         $this->session->clearStorage();
         $this->customerSession->clearStorage();
         $this->session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->formKey);
         $this->customerSession->setCustomerGroupId($this->customerGroupId);
         $this->customerSession->setCustomer($this->customerFactory->create()->setGroupId($this->customerGroupId));
     }
     return $result;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:20,代码来源:DepersonalizePlugin.php

示例9: testDelete

 public function testDelete()
 {
     $cookiePath = '/';
     $cookieDomain = 'example.com';
     /** @var PublicCookieMetadata|\PHPUnit_Framework_MockObject_MockObject $metadata */
     $metadata = $this->getMockBuilder('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata')->disableOriginalConstructor()->getMock();
     $this->cookieMetadataFactory->expects(static::once())->method('createCookieMetadata')->willReturn($metadata);
     $this->sessionManager->expects(static::once())->method('getCookiePath')->willReturn($cookiePath);
     $metadata->expects(static::once())->method('setPath')->with($cookiePath)->willReturnSelf();
     $this->sessionManager->expects(static::once())->method('getCookieDomain')->willReturn($cookieDomain);
     $metadata->expects(static::once())->method('setDomain')->with($cookieDomain)->willReturnSelf();
     $this->cookieManagerMock->expects(static::once())->method('deleteCookie')->with(FormKey::COOKIE_NAME, $metadata);
     $this->formKey->delete();
 }
开发者ID:IlyaGluschenko,项目名称:test001,代码行数:14,代码来源:FormKeyTest.php

示例10: execute

 /**
  * @inheritdoc
  */
 public function execute()
 {
     $response = $this->resultFactory->create(ResultFactory::TYPE_JSON);
     try {
         $publicHash = $this->getRequest()->getParam('public_hash');
         $customerId = $this->session->getCustomerId();
         $result = $this->command->execute(['public_hash' => $publicHash, 'customer_id' => $customerId])->get();
         $response->setData(['paymentMethodNonce' => $result['paymentMethodNonce']]);
     } catch (\Exception $e) {
         $this->logger->critical($e);
         return $this->processBadRequest($response);
     }
     return $response;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:17,代码来源:GetNonce.php

示例11: testToHtml

 /**
  * Run test toHtml method
  *
  * @param bool $customerId
  * @return void
  *
  * @dataProvider dataProviderToHtml
  */
 public function testToHtml($customerId)
 {
     $cacheData = false;
     $idQueryParam = 'id-query-param';
     $sessionId = 'session-id';
     $this->additional->setData('cache_lifetime', 789);
     $this->additional->setData('cache_key', 'cache-key');
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('view_block_abstract_to_html_before', ['block' => $this->additional]);
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with('advanced/modules_disable_output/Magento_Persistent', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn(false);
     // get cache
     $this->cacheStateMock->expects($this->at(0))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(true);
     // save cache
     $this->cacheStateMock->expects($this->at(1))->method('isEnabled')->with(\Magento\Persistent\Block\Header\Additional::CACHE_GROUP)->willReturn(false);
     $this->cacheMock->expects($this->once())->method('load')->willReturn($cacheData);
     $this->sidResolverMock->expects($this->never())->method('getSessionIdQueryParam')->with($this->sessionMock)->willReturn($idQueryParam);
     $this->sessionMock->expects($this->never())->method('getSessionId')->willReturn($sessionId);
     // call protected _toHtml method
     $sessionMock = $this->getMock('Magento\\Persistent\\Model\\Session', ['getCustomerId'], [], '', false);
     $this->persistentSessionHelperMock->expects($this->atLeastOnce())->method('getSession')->willReturn($sessionMock);
     $sessionMock->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($customerId);
     if ($customerId) {
         $this->assertEquals('<span><a  >Not you?</a></span>', $this->additional->toHtml());
     } else {
         $this->assertEquals('', $this->additional->toHtml());
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:34,代码来源:AdditionalTest.php

示例12: redirect

 /**
  * Set redirect into response
  *
  * @param \Magento\Framework\App\ResponseInterface $response
  * @param string $path
  * @param array $arguments
  * @return void
  */
 public function redirect(\Magento\Framework\App\ResponseInterface $response, $path, $arguments = array())
 {
     if ($this->_session->getCookieShouldBeReceived() && $this->_urlBuilder->getUseSession() && $this->_canUseSessionIdInParam) {
         $arguments += array('_query' => array($this->_sidResolver->getSessionIdQueryParam($this->_session) => $this->_session->getSessionId()));
     }
     $response->setRedirect($this->_urlBuilder->getUrl($path, $arguments));
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:15,代码来源:Redirect.php

示例13: updatePathParams

 /**
  * {@inheritdoc}
  *
  * @param array $arguments
  * @return array
  */
 public function updatePathParams(array $arguments)
 {
     if ($this->_session->getCookieShouldBeReceived() && $this->_sidResolver->getUseSessionInUrl() && $this->_canUseSessionIdInParam) {
         $arguments += ['_query' => [$this->_sidResolver->getSessionIdQueryParam($this->_session) => $this->_session->getSessionId()]];
     }
     return $arguments;
 }
开发者ID:nja78,项目名称:magento2,代码行数:13,代码来源:Redirect.php

示例14: getSafeSessionId

 /**
  * Get a hash of the session id.
  *
  * @return string|null
  */
 protected function getSafeSessionId()
 {
     if (!$this->safeSessionId) {
         // When there is no session id, safeSessionId will be set to null.
         // This will prevent the method call from getting cached (above
         // check will fail) and cause the session to be rechecked for a
         // session id on successive calls until a session id is retrieved.
         // Allowing this behavior in case a log call happens before the
         // session is started. Some calls may miss the session id but once
         // it is available, it will be retrieved, cached and attached to
         // later log calls.
         $sessionId = $this->session->getSessionId();
         $this->safeSessionId = $sessionId ? hash('sha256', $this->session->getSessionId()) : null;
     }
     return $this->safeSessionId;
 }
开发者ID:eBayEnterprise,项目名称:magento2-retail-order-management,代码行数:21,代码来源:LoggerContext.php

示例15: testGetDataWithCustomerFormData

 public function testGetDataWithCustomerFormData()
 {
     $customerId = 11;
     $customerFormData = ['customer' => ['email' => 'test1@test1.ua', 'default_billing' => 3, 'default_shipping' => 3, 'entity_id' => $customerId], 'address' => [3 => ['firstname' => 'firstname1', 'lastname' => 'lastname1', 'street' => ['street1', 'street2'], 'default_billing' => 3, 'default_shipping' => 3]]];
     $customer = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock();
     $address = $this->getMockBuilder('Magento\\Customer\\Model\\Address')->disableOriginalConstructor()->getMock();
     $collectionMock = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection')->disableOriginalConstructor()->getMock();
     $collectionMock->expects($this->once())->method('addAttributeToSelect')->with('*');
     $this->customerCollectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock);
     $collectionMock->expects($this->once())->method('getItems')->willReturn([$customer]);
     $customer->expects($this->once())->method('getData')->willReturn(['email' => 'test@test.ua', 'default_billing' => 2, 'default_shipping' => 2]);
     $customer->expects($this->once())->method('getId')->willReturn($customerId);
     $customer->expects($this->once())->method('getAddresses')->willReturn([$address]);
     $address->expects($this->atLeastOnce())->method('getId')->willReturn(2);
     $address->expects($this->once())->method('load')->with(2)->willReturnSelf();
     $address->expects($this->once())->method('getData')->willReturn(['firstname' => 'firstname', 'lastname' => 'lastname', 'street' => "street\nstreet"]);
     $helper = new ObjectManager($this);
     $dataProvider = $helper->getObject('\\Magento\\Customer\\Model\\Customer\\DataProvider', ['name' => 'test-name', 'primaryFieldName' => 'primary-field-name', 'requestFieldName' => 'request-field-name', 'eavValidationRules' => $this->eavValidationRulesMock, 'customerCollectionFactory' => $this->customerCollectionFactoryMock, 'eavConfig' => $this->getEavConfigMock()]);
     $reflection = new \ReflectionClass(get_class($dataProvider));
     $reflectionProperty = $reflection->getProperty('session');
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($dataProvider, $this->sessionMock);
     $this->sessionMock->expects($this->once())->method('getCustomerFormData')->willReturn($customerFormData);
     $this->sessionMock->expects($this->once())->method('unsCustomerFormData');
     $this->assertEquals([$customerId => $customerFormData], $dataProvider->getData());
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:26,代码来源:DataProviderTest.php


注:本文中的Magento\Framework\Session\SessionManagerInterface类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。