本文整理汇总了PHP中Magento\Framework\Session\Generic类的典型用法代码示例。如果您正苦于以下问题:PHP Generic类的具体用法?PHP Generic怎么用?PHP Generic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Generic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Customer\Model\Session $customerSession
* @param CustomerViewHelper $customerViewHelper
* @param \Magento\Framework\Session\Generic $testimonialSession
*/
public function __construct(\Magento\Framework\App\Helper\Context $context, \Magento\Customer\Model\Session $customerSession, CustomerViewHelper $customerViewHelper, \Magento\Framework\Session\Generic $testimonialSession)
{
$this->_customerSession = $customerSession;
$this->_customerViewHelper = $customerViewHelper;
$this->_data = $testimonialSession->getFormData(true);
parent::__construct($context);
}
示例2: setUp
/**
* Set up before test
*
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function setUp()
{
$this->_objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
$this->_installerMock = $this->getMock('\\Magento\\Install\\Model\\Installer', array('isApplicationInstalled'), array(), '', false);
$this->_installerMock->expects($this->any())->method('isApplicationInstalled')->will($this->returnValue(true));
$this->_blockMock = $this->getMock('\\Magento\\Install\\Block\\Locale', array(), array(), '', false);
$this->_layoutMock = $this->getMock('\\Magento\\Framework\\View\\Layout', array('getBlock', 'initMessages', 'addBlock'), array(), '', false);
$this->_layoutMock->expects($this->any())->method('initMessages')->withAnyParameters()->will($this->returnValue(true));
$this->_layoutMock->expects($this->any())->method('addBlock')->withAnyParameters()->will($this->returnValue(true));
$this->_viewMock = $this->getMockForAbstractClass('\\Magento\\Framework\\App\\ViewInterface', array(), '', false, false, true, array('getLayout'));
$this->_viewMock->expects($this->any())->method('getLayout')->withAnyParameters()->will($this->returnValue($this->_layoutMock));
$this->_requestMock = $this->_getClearMock('\\Magento\\Framework\\App\\RequestInterface');
$this->_responseMock = $this->_getClearMock('\\Magento\\Framework\\App\\ResponseInterface');
$this->_actionFlagMock = $this->_getClearMock('\\Magento\\Framework\\App\\ActionFlag');
$this->_contextMock = $this->getMock('\\Magento\\Framework\\App\\Action\\Context', array('getView', 'getRequest', 'getResponse', 'getActionFlag'), array(), '', false);
$this->_contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->_viewMock));
$this->_contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->_requestMock));
$this->_contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->_responseMock));
$this->_contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($this->_actionFlagMock));
$this->_blockContextMock = $this->getMock('\\Magento\\Framework\\View\\Element\\Template\\Context', array(), array(), '', false);
$this->_wizardMock = $this->getMock('\\Magento\\Install\\Model\\Wizard', array('getStepByRequest'), array(), '', false);
$this->_wizardMock->expects($this->any())->method('getStepByRequest')->withAnyParameters()->will($this->returnValue(false));
$this->_sessionMock = $this->getMock('\\Magento\\Framework\\Session\\Generic', array('getLocale'), array(), '', false);
$this->_sessionMock->expects($this->any())->method('getLocale')->will($this->returnValue(self::LOCALE));
$this->_block = $this->_objectManager->getObject('Magento\\Install\\Block\\Locale', array('context' => $this->_blockContextMock, 'installer' => $this->_installerMock, 'installWizard' => $this->_wizardMock, 'session' => $this->_sessionMock, 'data' => array()));
$this->_layoutMock->expects($this->any())->method('getBlock')->with('install.locale')->will($this->returnValue($this->_block));
$this->_controller = $this->_objectManager->getObject('Magento\\Install\\Controller\\Wizard\\Locale', array('context' => $this->_contextMock, 'configScope' => $this->_getClearMock('Magento\\Framework\\Config\\Scope'), 'installer' => $this->_getClearMock('Magento\\Install\\Model\\Installer'), 'wizard' => $this->_wizardMock, 'session' => $this->_sessionMock, 'dbUpdater' => $this->_getClearMock('Magento\\Framework\\Module\\UpdaterInterface'), 'storeManager' => $this->_getClearMock('Magento\\Store\\Model\\StoreManagerInterface'), 'appState' => $this->_getClearMock('Magento\\Framework\\App\\State')));
}
示例3: execute
/**
* Register form key in session from cookie value
*
* @return void
*/
public function execute()
{
$formKeyFromCookie = $this->_formKey->get();
if ($formKeyFromCookie) {
$this->_session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->_escaper->escapeHtml($formKeyFromCookie));
}
}
示例4: execute
/**
* Initiate a session for unregistered users. Send back the session id.
*
* @return void
*/
public function execute()
{
$this->session->start('frontend');
$this->session->setUserId(0);
$this->session->setUserType(UserIdentifier::USER_TYPE_GUEST);
$this->session->regenerateId(true);
}
示例5: savePaymentInQuote
/**
* Saves payment information in quote
*
* @param Object $response
* @return void
*/
public function savePaymentInQuote($response)
{
$quote = $this->quoteRepository->get($this->sessionTransparent->getQuoteId());
/** @var InfoInterface $payment */
$payment = $this->paymentManagement->get($quote->getId());
$payment->setAdditionalInformation('pnref', $response->getPnref());
$this->errorHandler->handle($payment, $response);
$this->paymentManagement->set($quote->getId(), $payment);
}
示例6: testExecute
public function testExecute()
{
//Data
$formKey = '<asdfaswqrwqe12>';
$escapedFormKey = 'asdfaswqrwqe12';
//Verification
$this->_formKey->expects($this->once())->method('get')->will($this->returnValue($formKey));
$this->_escaper->expects($this->once())->method('escapeHtml')->with($formKey)->will($this->returnValue($escapedFormKey));
$this->_session->expects($this->once())->method('setData')->with(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $escapedFormKey);
$this->_model->execute();
}
示例7: bindLocale
/**
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function bindLocale($observer)
{
$locale = $observer->getEvent()->getLocale();
if ($locale) {
$choosedLocale = $this->_session->getLocale();
if ($choosedLocale) {
$locale->setLocaleCode($choosedLocale);
}
}
return $this;
}
示例8: getEnteredData
/**
* Retrieve Entered Data by key
*
* @param string $key
* @return string|null
*/
public function getEnteredData($key)
{
if ($this->_enteredData === null) {
$this->_enteredData = $this->_wishlistSession->getData('sharing_form', true);
}
if (!$this->_enteredData || !isset($this->_enteredData[$key])) {
return null;
} else {
return $this->escapeHtml($this->_enteredData[$key]);
}
}
示例9: execute
/**
* Send request to PayfloPro gateway for get Secure Token
*
* @return ResultInterface
*/
public function execute()
{
$this->sessionTransparent->setQuoteId($this->sessionManager->getQuote()->getId());
$token = $this->secureTokenService->requestToken($this->sessionManager->getQuote());
$result = [];
$result[$this->transparent->getCode()]['fields'] = $token->getData();
$result['success'] = $token->getSecuretoken() ? true : false;
if (!$result['success']) {
$result['error'] = true;
$result['error_messages'] = __('Secure Token Error. Try again.');
}
return $this->resultJsonFactory->create()->setData($result);
}
示例10: getFormData
/**
* Retrieve configuration form data object
*
* @return \Magento\Framework\Object
*/
public function getFormData()
{
$data = $this->getData('form_data');
if (is_null($data)) {
$data = $this->_session->getConfigData(true);
if (empty($data)) {
$data = $this->_installerConfig->getFormData();
} else {
$data = new \Magento\Framework\Object($data);
}
$this->setFormData($data);
}
return $data;
}
示例11: testSavePaymentInQuote
public function testSavePaymentInQuote()
{
$quoteId = 1;
$response = new DataObject();
$payment = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Payment')->disableOriginalConstructor()->getMock();
$payment->expects($this->once())->method('setAdditionalInformation')->with('pnref');
$this->errorHandlerMock->expects($this->once())->method('handle')->with($payment, $response);
$quote = $this->getMock('Magento\\Quote\\Api\\Data\\CartInterface', [], [], '', false);
$quote->expects($this->exactly(2))->method('getId')->willReturn($quoteId);
$this->sessionTransparent->expects($this->once())->method('getQuoteId')->willReturn($quoteId);
$this->quoteRepository->expects($this->once())->method('get')->willReturn($quote);
$this->paymentMethodManagementInterface->expects($this->once())->method('get')->willReturn($payment);
$this->paymentMethodManagementInterface->expects($this->once())->method('set');
$this->model->savePaymentInQuote($response);
}
示例12: execute
/**
* Check CAPTCHA on New Testmonial page
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$formId = 'testimonial_new';
$captcha = $this->_helper->getCaptcha($formId);
if ($captcha->isRequired()) {
/** @var \Magento\Framework\App\Action\Action $controller */
$controller = $observer->getControllerAction();
if (!$captcha->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) {
$this->_testimonialSession->setFormData($controller->getRequest()->getPost());
$this->messageManager->addError(__('Incorrect CAPTCHA.'));
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), $this->redirect->getRefererUrl());
}
}
}
示例13: execute
/**
* Login registered users and initiate a session. Send back the session id.
*
* Expects a POST. ex for JSON {"username":"user@magento.com", "password":"userpassword"}
*
* @return void
*/
public function execute()
{
$contentTypeHeaderValue = $this->getRequest()->getHeader('Content-Type');
$contentType = $this->getContentType($contentTypeHeaderValue);
$loginData = null;
try {
$loginData = $this->deserializerFactory->get($contentType)->deserialize($this->getRequest()->getRawBody());
} catch (Exception $e) {
$this->getResponse()->setHttpResponseCode($e->getCode());
return;
}
if (!$loginData || $this->getRequest()->getMethod() !== \Magento\Webapi\Model\Rest\Config::HTTP_METHOD_POST) {
$this->getResponse()->setHttpResponseCode(HttpException::HTTP_BAD_REQUEST);
return;
}
$customerData = null;
try {
$customerData = $this->customerAccountService->authenticate($loginData['username'], $loginData['password']);
} catch (AuthenticationException $e) {
$this->getResponse()->setHttpResponseCode(HttpException::HTTP_UNAUTHORIZED);
return;
}
$this->session->start('frontend');
$this->session->setUserId($customerData->getId());
$this->session->setUserType(UserIdentifier::USER_TYPE_CUSTOMER);
$this->session->regenerateId(true);
}
示例14: testGetSessionIdQueryParamCustom
public function testGetSessionIdQueryParamCustom()
{
$oldSessionName = $this->session->getName();
$this->session->setName($this->customSessionName);
$this->assertEquals($this->customSessionQueryParam, $this->model->getSessionIdQueryParam($this->session));
$this->session->setName($oldSessionName);
}
示例15: testSessionUrlVarWithoutMatchedHostsAndBaseUrl
public function testSessionUrlVarWithoutMatchedHostsAndBaseUrl()
{
$requestMock = $this->getRequestMock();
$model = $this->getUrlModel(
[
'session' => $this->sessionMock,
'request' => $requestMock,
'sidResolver' => $this->sidResolverMock,
'scopeResolver' => $this->scopeResolverMock,
'routeParamsResolverFactory' => $this->getRouteParamsResolverFactory(),
]
);
$requestMock->expects($this->once())->method('getHttpHost')->will($this->returnValue('localhost'));
$this->scopeMock->expects($this->once())
->method('getBaseUrl')
->will($this->returnValue('http://example.com'));
$this->scopeResolverMock->expects($this->any())
->method('getScope')
->will($this->returnValue($this->scopeMock));
$this->sidResolverMock->expects($this->once())->method('getSessionIdQueryParam')
->will($this->returnValue('SID'));
$this->sessionMock->expects($this->once())->method('getSessionId')
->will($this->returnValue('session-id'));
$this->assertEquals(
'<a href="http://example.com/?SID=session-id">www.example.com</a>',
$model->sessionUrlVar('<a href="http://example.com/?___SID=U">www.example.com</a>')
);
}