本文整理汇总了PHP中Magento\Framework\App\Request\Http类的典型用法代码示例。如果您正苦于以下问题:PHP Http类的具体用法?PHP Http怎么用?PHP Http使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Http类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Handle private content version cookie
* Set cookie if it is not set.
* Increment version on post requests.
* In all other cases do nothing.
*
* @return void
*/
public function process()
{
if ($this->request->isPost()) {
$publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDuration(self::COOKIE_PERIOD)->setPath('/')->setHttpOnly(false);
$this->cookieManager->setPublicCookie(self::COOKIE_NAME, $this->generateValue(), $publicCookieMetadata);
}
}
示例2: aroundExecute
/**
* @param \Magento\Framework\App\ActionInterface $subject
* @param callable $proceed
* @param \Magento\Framework\App\RequestInterface $request
* @return mixed
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundExecute(
\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);
}
示例3: setUp
protected function setUp()
{
$orderId = 1;
$shipmentId = 1;
$shipment = [];
$tracking = [];
$this->shipmentLoaderMock = $this->getMock('Magento\\Shipping\\Controller\\Adminhtml\\Order\\ShipmentLoader', ['setOrderId', 'setShipmentId', 'setShipment', 'setTracking', 'load'], [], '', false);
$this->requestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false);
$this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
$this->responseMock = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
$this->sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', ['setIsUrlNotice'], [], '', false);
$this->actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', ['get'], [], '', false);
$this->shipmentMock = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['__wakeup'], [], '', false);
$this->fileFactoryMock = $this->getMock('Magento\\Framework\\App\\Response\\Http\\FileFactory', ['create'], [], '', false);
$contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getObjectManager', 'getResponse', 'getSession', 'getActionFlag'], [], '', false);
$contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock));
$contextMock->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManagerMock));
$contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock));
$contextMock->expects($this->any())->method('getSession')->will($this->returnValue($this->sessionMock));
$contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($this->actionFlag));
$this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId));
$this->requestMock->expects($this->at(1))->method('getParam')->with('shipment_id')->will($this->returnValue($shipmentId));
$this->requestMock->expects($this->at(2))->method('getParam')->with('shipment')->will($this->returnValue($shipment));
$this->requestMock->expects($this->at(3))->method('getParam')->with('tracking')->will($this->returnValue($tracking));
$this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId);
$this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId);
$this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment);
$this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking);
$this->controller = new \Magento\Shipping\Controller\Adminhtml\Order\Shipment\PrintPackage($contextMock, $this->shipmentLoaderMock, $this->fileFactoryMock);
}
示例4: testProcess
/**
* @dataProvider processProvider
* @param bool $isPost
*/
public function testProcess($isPost)
{
$this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost));
if ($isPost) {
$publicCookieMetadataMock = $this->getMock('Magento\Framework\Stdlib\Cookie\PublicCookieMetadata');
$publicCookieMetadataMock->expects($this->once())
->method('setPath')
->with('/')
->will($this->returnSelf());
$publicCookieMetadataMock->expects($this->once())
->method('setDuration')
->with(Version::COOKIE_PERIOD)
->will($this->returnSelf());
$publicCookieMetadataMock->expects($this->once())
->method('setHttpOnly')
->with(false)
->will($this->returnSelf());
$this->cookieMetadataFactoryMock->expects($this->once())
->method('createPublicCookieMetadata')
->with()
->will(
$this->returnValue($publicCookieMetadataMock)
);
$this->cookieManagerMock->expects($this->once())
->method('setPublicCookie');
}
$this->version->process();
}
示例5: afterDispatch
/**
* Set Cookie for msg box when it displays first
*
* @param FrontController $subject
* @param \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface $result
*
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterDispatch(FrontController $subject, $result)
{
if ($this->request->isPost() && $this->messageManager->hasMessages()) {
$publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDuration(self::COOKIE_PERIOD)->setPath('/')->setHttpOnly(false);
$this->cookieManager->setPublicCookie(self::COOKIE_NAME, 1, $publicCookieMetadata);
}
return $result;
}
示例6: _beforeSave
/**
* Before model save
* @param \Magefan\Blog\Model\Post $model
* @param \Magento\Framework\App\Request\Http $request
* @return void
*/
protected function _beforeSave($model, $request)
{
/* Prepare dates */
$dateFilter = $this->_objectManager->create('Magento\\Framework\\Stdlib\\DateTime\\Filter\\Date');
$data = $model->getData();
$filterRules = [];
foreach (['publish_time', 'custom_theme_from', 'custom_theme_to'] as $dateField) {
if (!empty($data[$dateField])) {
$filterRules[$dateField] = $dateFilter;
}
}
$inputFilter = new \Zend_Filter_Input($filterRules, [], $data);
$data = $inputFilter->getUnescaped();
$model->setData($data);
/* Prepare author */
if (!$model->getAuthorId()) {
$authSession = $this->_objectManager->get('Magento\\Backend\\Model\\Auth\\Session');
$model->setAuthorId($authSession->getUser()->getId());
}
/* Prepare relative links */
$data = $request->getPost('data');
$links = isset($data['links']) ? $data['links'] : null;
if ($links && is_array($links)) {
foreach (['post', 'product'] as $linkType) {
if (!empty($links[$linkType]) && is_array($links[$linkType])) {
$linksData = [];
foreach ($links[$linkType] as $item) {
$linksData[$item['id']] = ['position' => $item['position']];
}
$links[$linkType] = $linksData;
}
}
$model->setData('links', $links);
}
/* Prepare images */
$data = $model->getData();
foreach (['featured_img', 'og_img'] as $key) {
if (isset($data[$key]) && is_array($data[$key])) {
if (!empty($data[$key]['delete'])) {
$model->setData($key, null);
} else {
if (isset($data[$key][0]['name']) && isset($data[$key][0]['tmp_name'])) {
$image = $data[$key][0]['name'];
$model->setData($key, Post::BASE_MEDIA_PATH . DIRECTORY_SEPARATOR . $image);
$imageUploader = $this->_objectManager->get('Magefan\\Blog\\ImageUpload');
$imageUploader->moveFileFromTmp($image);
} else {
if (isset($data[$key][0]['name'])) {
$model->setData($key, $data[$key][0]['name']);
}
}
}
} else {
$model->setData($key, null);
}
}
}
示例7: log
/**
* {@inheritdoc}
*/
public function log($message, $level)
{
$message .= ' ' . $this->request->getRequestUri();
if ($this->logLevel >= $level) {
switch ($level) {
case self::EMERGENCY:
$this->logger->emergency($message);
break;
case self::ALERT:
$this->logger->alert($message);
break;
case self::CRITICAL:
$this->logger->critical($message);
break;
case self::ERROR:
$this->logger->error($message);
break;
case self::WARNING:
$this->logger->warning($message);
break;
case self::NOTICE:
$this->logger->notice($message);
break;
case self::INFO:
$this->logger->info($message);
break;
default:
$this->logger->debug($message);
}
}
}
示例8: testLog
/**
* @dataProvider logDataProvider
*/
public function testLog($logLevel, $method)
{
$message = 'Error message';
$this->request->expects($this->once())->method('getRequestUri')->willReturn($this->requestUri);
$this->psrLogger->expects($this->once())->method($method)->with($message . ' ' . $this->requestUri);
$this->logger->log($message, $logLevel);
}
示例9: testDispatchPostDispatch
public function testDispatchPostDispatch()
{
$this->_requestMock->expects($this->exactly(3))->method('getFullActionName')->will($this->returnValue(self::FULL_ACTION_NAME));
$this->_requestMock->expects($this->exactly(2))->method('getRouteName')->will($this->returnValue(self::ROUTE_NAME));
$expectedEventParameters = ['controller_action' => $this->action, 'request' => $this->_requestMock];
$this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with('controller_action_predispatch', $expectedEventParameters);
$this->_eventManagerMock->expects($this->at(1))->method('dispatch')->with('controller_action_predispatch_' . self::ROUTE_NAME, $expectedEventParameters);
$this->_eventManagerMock->expects($this->at(2))->method('dispatch')->with('controller_action_predispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters);
$this->_requestMock->expects($this->once())->method('isDispatched')->will($this->returnValue(true));
$this->_actionFlagMock->expects($this->at(0))->method('get')->with('', Action::FLAG_NO_DISPATCH)->will($this->returnValue(false));
// _forward expectations
$this->_requestMock->expects($this->once())->method('initForward');
$this->_requestMock->expects($this->once())->method('setParams')->with(self::$actionParams);
$this->_requestMock->expects($this->once())->method('setControllerName')->with(self::CONTROLLER_NAME);
$this->_requestMock->expects($this->once())->method('setModuleName')->with(self::MODULE_NAME);
$this->_requestMock->expects($this->once())->method('setActionName')->with(self::ACTION_NAME);
$this->_requestMock->expects($this->once())->method('setDispatched')->with(false);
// _redirect expectations
$this->_redirectMock->expects($this->once())->method('redirect')->with($this->_responseMock, self::FULL_ACTION_NAME, self::$actionParams);
$this->_actionFlagMock->expects($this->at(1))->method('get')->with('', Action::FLAG_NO_POST_DISPATCH)->will($this->returnValue(false));
$this->_eventManagerMock->expects($this->at(3))->method('dispatch')->with('controller_action_postdispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters);
$this->_eventManagerMock->expects($this->at(4))->method('dispatch')->with('controller_action_postdispatch_' . self::ROUTE_NAME, $expectedEventParameters);
$this->_eventManagerMock->expects($this->at(5))->method('dispatch')->with('controller_action_postdispatch', $expectedEventParameters);
$this->assertEquals($this->_responseMock, $this->action->dispatch($this->_requestMock));
}
示例10: afterDispatch
/**
* Set Cookie for msg box when it displays first
*
* @param \Magento\Framework\App\FrontController $subject
* @param \Magento\Framework\App\ResponseInterface $response
*
* @return \Magento\Framework\App\ResponseInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterDispatch(\Magento\Framework\App\FrontController $subject, \Magento\Framework\App\ResponseInterface $response)
{
if ($this->request->isPost() && $this->messageManager->hasMessages()) {
$this->cookie->set(self::COOKIE_NAME, 1, self::COOKIE_PERIOD, '/');
}
return $response;
}
示例11: 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);
}
示例12: testExecute
/**
* Run test execute method
*/
public function testExecute()
{
$orderId = 1;
$shipmentId = 1;
$shipment = [];
$tracking = [];
$result = 'result-html';
$layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', ['createBlock'], [], '', false);
$gridMock = $this->getMock('Magento\\Shipping\\Block\\Adminhtml\\Order\\Packaging\\Grid', ['setIndex', 'toHtml'], [], '', false);
$this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId));
$this->requestMock->expects($this->at(1))->method('getParam')->with('shipment_id')->will($this->returnValue($shipmentId));
$this->requestMock->expects($this->at(2))->method('getParam')->with('shipment')->will($this->returnValue($shipment));
$this->requestMock->expects($this->at(3))->method('getParam')->with('tracking')->will($this->returnValue($tracking));
$this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId);
$this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId);
$this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment);
$this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking);
$this->shipmentLoaderMock->expects($this->once())->method('load');
$layoutMock->expects($this->once())->method('createBlock')->with('Magento\\Shipping\\Block\\Adminhtml\\Order\\Packaging\\Grid')->will($this->returnValue($gridMock));
$this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock));
$this->responseMock->expects($this->once())->method('setBody')->with($result)->will($this->returnSelf());
$this->requestMock->expects($this->at(4))->method('getParam')->with('index');
$gridMock->expects($this->once())->method('setIndex')->will($this->returnSelf());
$gridMock->expects($this->once())->method('toHtml')->will($this->returnValue($result));
$this->assertNotEmpty('result-html', $this->controller->execute());
}
示例13: testGetViewFileUrl
/**
* @param bool $isSecure
* @dataProvider getViewFileUrlDataProvider
*/
public function testGetViewFileUrl($isSecure)
{
$this->request->expects($this->once())->method('isSecure')->will($this->returnValue($isSecure));
$this->assetRepo->expects($this->once())->method('getUrlWithParams')->with('some file', $this->callback(function ($value) use($isSecure) {
return isset($value['_secure']) && $value['_secure'] === $isSecure;
}))->will($this->returnValue('result url'));
$this->assertEquals('result url', $this->model->getViewFileUrl('some file'));
}
示例14: testGetScopeTitleDefault
public function testGetScopeTitleDefault()
{
$scope = 'default';
$scopeId = 0;
$scopeTypeName = 'Default';
$this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
$this->assertEquals($scopeTypeName, $this->block->getScopeTitle()->render());
}
示例15: testProcess
/**
* @dataProvider processProvider
* @param bool $isPost
*/
public function testProcess($isPost)
{
$this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost));
if ($isPost) {
$this->cookieMock->expects($this->once())->method('set');
}
$this->version->process();
}