本文整理汇总了PHP中Magento\Framework\App\Response\Http类的典型用法代码示例。如果您正苦于以下问题:PHP Http类的具体用法?PHP Http怎么用?PHP Http使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Http类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: beforeSendResponse
/**
* Set proper value of X-Magento-Vary cookie.
*
* @param \Magento\Framework\App\Response\Http $subject
* @return void
*/
public function beforeSendResponse(\Magento\Framework\App\Response\Http $subject)
{
if ($subject instanceof \Magento\Framework\App\PageCache\NotCacheableInterface) {
return;
}
$subject->sendVary();
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:13,代码来源:HttpPlugin.php
示例2: beforeSendResponse
/**
* @param \Magento\Framework\App\Response\Http $subject
* @return void
* @codeCoverageIgnore
*/
public function beforeSendResponse(\Magento\Framework\App\Response\Http $subject)
{
foreach ($this->headerProviders as $provider) {
if ($provider->canApply()) {
$subject->setHeader($provider->getName(), $provider->getValue());
}
}
}
开发者ID:VoblaSmile,项目名称:php56-magento2-data,代码行数:13,代码来源:HeaderManager.php
示例3: aroundDispatch
/**
* Call method around dispatch frontend action
*
* @param FrontControllerInterface $subject
* @param \Closure $proceed
* @param RequestInterface $request
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD)
*/
public function aroundDispatch(FrontControllerInterface $subject, \Closure $proceed, RequestInterface $request)
{
$startTime = microtime(true);
if (isset($_SERVER['REQUEST_TIME_FLOAT'])) {
$startTime = $_SERVER['REQUEST_TIME_FLOAT'];
}
/** @var \Magento\Framework\App\Request\Http $request */
if (strpos($request->getOriginalPathInfo(), 'searchautocomplete/ajax/suggest') !== false) {
$this->result->init();
$proceed($request);
#require for init translations
$request->setControllerModule('Magento_CatalogSearch');
$request->setDispatched(true);
$identifier = 'QUERY_' . $this->storeManager->getStore()->getId() . '_' . md5($request->getParam('q'));
if ($result = $this->cache->load($identifier)) {
$result = \Zend_Json::decode($result);
$result['time'] = round(microtime(true) - $startTime, 4);
$result['cache'] = true;
$data = \Zend_Json::encode($result);
} else {
// mirasvit core event
$this->eventManager->dispatch('core_register_urlrewrite');
$result = $this->result->toArray();
$result['success'] = true;
$result['time'] = round(microtime(true) - $startTime, 4);
$result['cache'] = false;
$data = \Zend_Json::encode($result);
$this->cache->save($data, $identifier, [\Magento\PageCache\Model\Cache\Type::CACHE_TAG]);
}
$this->response->setPublicHeaders(3600);
return $this->response->representJson($data);
} else {
return $proceed($request);
}
}
开发者ID:Doability,项目名称:magento2dev,代码行数:45,代码来源:Plugin.php
示例4: sendResponse
/**
* Send response
*
* @return void
*/
public function sendResponse()
{
if ($this->_filePath && $this->getHttpResponseCode() == 200) {
$this->_transferAdapter->send($this->_filePath);
} else {
parent::sendResponse();
}
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:13,代码来源:Response.php
示例5: testProcessNotSaveCache
/**
* @dataProvider processNotSaveCacheProvider
* @param string $cacheControlHeader
* @param int $httpCode
* @param bool $isGet
* @param bool $overrideHeaders
*/
public function testProcessNotSaveCache($cacheControlHeader, $httpCode, $isGet, $overrideHeaders)
{
$this->responseMock->expects($this->once())->method('getHeader')->with('Cache-Control')->will($this->returnValue(array('value' => $cacheControlHeader)));
$this->responseMock->expects($this->any())->method('getHttpResponseCode')->will($this->returnValue($httpCode));
$this->requestMock->expects($this->any())->method('isGet')->will($this->returnValue($isGet));
if ($overrideHeaders) {
$this->responseMock->expects($this->once())->method('setNoCacheHeaders');
}
$this->cacheMock->expects($this->never())->method('save');
$this->kernel->process($this->responseMock);
}
开发者ID:Atlis,项目名称:docker-magento2,代码行数:18,代码来源:KernelTest.php
示例6: testExecute
public function testExecute()
{
$this->objectManager->expects($this->once())->method('get')->with('Magento\\Theme\\Helper\\Storage')->willReturn($this->storageHelper);
$this->storageHelper->expects($this->once())->method('getRelativeUrl')->willReturn('http://relative.url/');
$this->response->expects($this->once())->method('setBody')->with('http://relative.url/');
$this->controller->execute();
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:7,代码来源:OnInsertTest.php
示例7: dispatch
/**
* Perform action and generate response
*
* @param RequestInterface $request
* @return ResponseInterface|\Magento\Framework\Controller\ResultInterface
* @throws \LogicException
*/
public function dispatch(RequestInterface $request)
{
\Magento\Framework\Profiler::start('routers_match');
$routingCycleCounter = 0;
$result = null;
while (!$request->isDispatched() && $routingCycleCounter++ < 100) {
/** @var \Magento\Framework\App\RouterInterface $router */
foreach ($this->_routerList as $router) {
try {
$actionInstance = $router->match($request);
if ($actionInstance) {
$request->setDispatched(true);
$this->response->setNoCacheHeaders();
if ($actionInstance instanceof \Magento\Framework\App\Action\AbstractAction) {
$result = $actionInstance->dispatch($request);
} else {
$result = $actionInstance->execute();
}
break;
}
} catch (\Magento\Framework\Exception\NotFoundException $e) {
$request->initForward();
$request->setActionName('noroute');
$request->setDispatched(false);
break;
}
}
}
\Magento\Framework\Profiler::stop('routers_match');
if ($routingCycleCounter > 100) {
throw new \LogicException('Front controller reached 100 router match iterations');
}
return $result;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:41,代码来源:FrontController.php
示例8: testDisplay
public function testDisplay()
{
$this->markTestSkipped('Remove it when task(MAGETWO-33495) will be fixed');
$this->_response->expects($this->atLeastOnce())->method('sendHeaders');
$this->_request->expects($this->atLeastOnce())->method('getHeader');
$stat = (include __DIR__ . '/_files/timers.php');
$this->_output->display($stat);
$actualHeaders = $this->_response->getHeaders();
$this->assertNotEmpty($actualHeaders);
$actualProtocol = false;
$actualProfilerData = false;
foreach ($actualHeaders as $oneHeader) {
$headerName = $oneHeader->getFieldName();
$headerValue = $oneHeader->getFieldValue();
if (!$actualProtocol && $headerName == 'X-Wf-Protocol-1') {
$actualProtocol = $headerValue;
}
if (!$actualProfilerData && $headerName == 'X-Wf-1-1-1-1') {
$actualProfilerData = $headerValue;
}
}
$this->assertNotEmpty($actualProtocol, 'Cannot get protocol header');
$this->assertNotEmpty($actualProfilerData, 'Cannot get profiler header');
$this->assertContains('Protocol/JsonStream', $actualProtocol);
$this->assertRegExp('/"Type":"TABLE","Label":"Code Profiler \\(Memory usage: real - \\d+, emalloc - \\d+\\)"/', $actualProfilerData);
$this->assertContains('[' . '["Timer Id","Time","Avg","Cnt","Emalloc","RealMem"],' . '["root","0.080000","0.080000","1","1,000","50,000"],' . '[". init","0.040000","0.040000","1","200","2,500"],' . '[". . init_store","0.020000","0.010000","2","100","2,000"],' . '["system","0.030000","0.015000","2","400","20,000"]' . ']', $actualProfilerData);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:27,代码来源:FirebugTest.php
示例9: testAroundDispatchDisabled
/**
* @dataProvider dataProvider
*/
public function testAroundDispatchDisabled($state)
{
$this->configMock->expects($this->any())->method('getType')->will($this->returnValue(null));
$this->versionMock->expects($this->never())->method('process');
$this->stateMock->expects($this->any())->method('getMode')->will($this->returnValue($state));
$this->responseMock->expects($this->never())->method('setHeader');
$this->plugin->aroundDispatch($this->frontControllerMock, $this->closure, $this->requestMock);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:11,代码来源:VarnishPluginTest.php
示例10: testExecuteWithWrongRequest
public function testExecuteWithWrongRequest()
{
$this->request->expects($this->once())->method('isPost')->willReturn(false);
$jsonData = $this->getMock('Magento\\Framework\\Json\\Helper\\Data', [], [], '', false);
$jsonData->expects($this->once())->method('jsonEncode')->with(['error' => true, 'message' => 'Wrong request'])->willReturn('{"error":"true","message":"Wrong request"}');
$this->objectManager->expects($this->once())->method('get')->with('Magento\\Framework\\Json\\Helper\\Data')->willReturn($jsonData);
$this->response->expects($this->once())->method('representJson')->with('{"error":"true","message":"Wrong request"}');
$this->controller->execute();
}
开发者ID:Doability,项目名称:magento2dev,代码行数:9,代码来源:DeleteFilesTest.php
示例11: afterGetLoadedProductCollection
/**
* @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $resultCollection
* @param \Magento\Catalog\Block\Product\ListProduct $subject
* @return \Magento\Eav\Model\Entity\Collection\AbstractCollection $resultCollection
*/
public function afterGetLoadedProductCollection(\Magento\Catalog\Block\Product\ListProduct $subject, $resultCollection)
{
if ($resultCollection->count() == 1) {
/** @var \Magento\Catalog\Model\Product $product */
$product = $resultCollection->getFirstItem();
$this->response->setRedirect($product->getProductUrl());
}
return $resultCollection;
}
开发者ID:rogyar,项目名称:FirstProduct,代码行数:14,代码来源:ListProduct.php
示例12: testAuthenticate
public function testAuthenticate()
{
$urlMock = $this->getMock('Magento\\Framework\\Url', [], [], '', false);
$urlMock->expects($this->exactly(2))->method('getUrl')->will($this->returnValue(''));
$urlMock->expects($this->once())->method('getRebuiltUrl')->will($this->returnValue(''));
$this->urlFactoryMock->expects($this->exactly(3))->method('create')->will($this->returnValue($urlMock));
$this->responseMock->expects($this->once())->method('setRedirect')->with('')->will($this->returnValue(''));
$this->assertFalse($this->_model->authenticate());
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:9,代码来源:SessionTest.php
示例13: testExecuteWithWishlist
public function testExecuteWithWishlist()
{
$wishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
$this->wishlistProvider->expects($this->once())->method('getWishlist')->willReturn($wishlist);
$this->request->expects($this->once())->method('getParam')->with('qty')->will($this->returnValue(2));
$this->itemCarrier->expects($this->once())->method('moveAllToCart')->with($wishlist, 2)->will($this->returnValue('http://redirect-url.com'));
$this->response->expects($this->once())->method('setRedirect')->will($this->returnValue('http://redirect-url.com'));
$controller = $this->getController();
$controller->execute();
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:10,代码来源:AllcartTest.php
示例14: testExecuteLocalizedException
/**
* Executes the controller action and asserts non exception logic
*/
public function testExecuteLocalizedException()
{
$phrase = new \Magento\Framework\Phrase('some error');
$objectManager = new ObjectManager($this);
$this->vault->expects($this->once())->method('processNonce')->willThrowException(new LocalizedException($phrase));
$this->resultJson->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => 'some error']);
$this->resultFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
$this->messageManager->expects($this->once())->method('addError')->with($phrase);
$notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\AjaxSave', ['request' => $this->request, 'resultFactory' => $this->resultFactory, 'vault' => $this->vault, 'messageManager' => $this->messageManager]);
$this->assertSame($this->resultJson, $notification->execute());
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:14,代码来源:AjaxSaveTest.php
示例15: testAroundResultWithPluginDeveloperMode
public function testAroundResultWithPluginDeveloperMode()
{
$this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->willReturn(true);
$this->state->expects($this->once())->method('getMode')->willReturn(\Magento\Framework\App\State::MODE_DEVELOPER);
$this->header->expects($this->any())->method('getFieldValue')->willReturnOnConsecutiveCalls('test', 'tag,tag2');
$this->response->expects($this->any())->method('setHeader')->withConsecutive(['X-Magento-Cache-Control', 'test'], ['X-Magento-Cache-Debug', 'MISS', true], ['X-Magento-Tags', 'tag,tag2,' . \Magento\PageCache\Model\Cache\Type::CACHE_TAG]);
$this->response->expects($this->once())->method('clearHeader')->with('X-Magento-Tags');
$this->registry->expects($this->once())->method('registry')->with('use_page_cache_plugin')->will($this->returnValue(true));
$this->kernel->expects($this->once())->method('process')->with($this->response);
$result = call_user_func($this->closure);
$this->assertSame($result, $this->plugin->aroundRenderResult($this->subject, $this->closure, $this->response));
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:BuiltinPluginTest.php
示例16: testExecuteInternalLocalizedException
/**
* Executes the controller action and asserts non exception logic
*/
public function testExecuteInternalLocalizedException()
{
$phrase = new \Magento\Framework\Phrase('Something went wrong while processing.');
$objectManager = new ObjectManager($this);
$this->vault->expects($this->once())->method('generatePaymentMethodToken')->willThrowException(new LocalizedException($phrase));
$this->resultJson->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => 'Something went wrong while processing.']);
$this->resultFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
$this->messageManager->expects($this->once())->method('addError')->with($phrase);
$this->request->expects($this->any())->method('getParam')->willReturn(true);
/** @var \Magento\Braintree\Controller\Creditcard\Generate $controller */
$controller = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Generate', ['request' => $this->request, 'resultFactory' => $this->resultFactory, 'vault' => $this->vault, 'messageManager' => $this->messageManager]);
$this->assertSame($this->resultJson, $controller->executeInternal());
}
开发者ID:nblair,项目名称:magescotch,代码行数:16,代码来源:GenerateTest.php
示例17: testRepresentJson
/**
* Test setting body in JSON format
*/
public function testRepresentJson()
{
$this->_model->setHeader('Content-Type', 'text/javascript');
$this->_model->representJson('json_string');
$this->assertEquals('application/json', $this->_model->getHeader('Content-Type')['value']);
$this->assertEquals('json_string', $this->_model->getBody('default'));
}
开发者ID:Atlis,项目名称:docker-magento2,代码行数:10,代码来源:HttpTest.php
示例18: redirectSection
/**
* Redirect into response section
*
* @return void
*/
protected function redirectSection()
{
$this->actionFlag->expects($this->once())->method('get')->with('', \Magento\Backend\App\AbstractAction::FLAG_IS_URLS_CHECKED)->will($this->returnValue(true));
$this->sessionMock->expects($this->once())->method('setIsUrlNotice')->with(true);
$this->helperMock->expects($this->once())->method('getUrl')->will($this->returnValue('redirect-path'));
$this->responseMock->expects($this->once())->method('setRedirect');
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:12,代码来源:PrintLabelTest.php
示例19: testExecute
/**
* Run test execute method
*/
public function testExecute()
{
$data = ['comment' => 'comment'];
$result = 'result-html';
$orderId = 1;
$shipmentId = 1;
$shipment = [];
$tracking = [];
$resultLayoutMock = $this->getMock('Magento\\Framework\\View\\Result\\Layout', ['getBlock', 'getDefaultLayoutHandle', 'addDefaultHandle', 'getLayout'], [], '', false);
$this->requestMock->expects($this->once())->method('setParam')->with('shipment_id', $shipmentId);
$this->requestMock->expects($this->once())->method('getPost')->with('comment')->will($this->returnValue($data));
$this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap([['id', null, $shipmentId], ['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipment], ['tracking', null, $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')->will($this->returnValue($this->shipmentMock));
$this->shipmentMock->expects($this->once())->method('addComment');
$this->shipmentCommentSenderMock->expects($this->once())->method('send');
$this->shipmentMock->expects($this->once())->method('save');
$layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', ['getBlock'], [], '', false);
$blockMock = $this->getMock('Magento\\Shipping\\Block\\Adminhtml\\View\\Comments', ['toHtml'], [], '', false);
$blockMock->expects($this->once())->method('toHtml')->willReturn($result);
$layoutMock->expects($this->once())->method('getBlock')->with('shipment_comments')->willReturn($blockMock);
$resultLayoutMock->expects($this->once())->method('getLayout')->willReturn($layoutMock);
$resultLayoutMock->expects($this->once())->method('addDefaultHandle');
$this->resultLayoutFactoryMock->expects($this->once())->method('create')->will($this->returnValue($resultLayoutMock));
$this->responseMock->expects($this->once())->method('setBody')->with($result);
$this->assertNull($this->controller->execute());
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:33,代码来源:AddCommentTest.php
示例20: testExecute
public function testExecute()
{
$blocks = ['block1', 'block2'];
$handles = ['handle1', 'handle2'];
$originalRequest = '{"route":"route","controller":"controller","action":"action","uri":"uri"}';
$expectedData = ['block1' => 'data1', 'block2' => 'data2'];
$blockInstance1 = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false);
$blockInstance1->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block1']));
$blockInstance2 = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', ['toHtml'], [], '', false);
$blockInstance2->expects($this->once())->method('toHtml')->will($this->returnValue($expectedData['block2']));
$this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(true));
$this->requestMock->expects($this->at(1))->method('getRouteName')->will($this->returnValue('magento_pagecache'));
$this->requestMock->expects($this->at(2))->method('getControllerName')->will($this->returnValue('block'));
$this->requestMock->expects($this->at(3))->method('getActionName')->will($this->returnValue('render'));
$this->requestMock->expects($this->at(4))->method('getRequestUri')->will($this->returnValue('uri'));
$this->requestMock->expects($this->at(5))->method('getParam')->with($this->equalTo('originalRequest'))->will($this->returnValue($originalRequest));
$this->requestMock->expects($this->at(10))->method('getParam')->with($this->equalTo('blocks'), $this->equalTo(''))->will($this->returnValue(json_encode($blocks)));
$this->requestMock->expects($this->at(11))->method('getParam')->with($this->equalTo('handles'), $this->equalTo(''))->will($this->returnValue(json_encode($handles)));
$this->viewMock->expects($this->once())->method('loadLayout')->with($this->equalTo($handles));
$this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock));
$this->layoutMock->expects($this->at(0))->method('getBlock')->with($this->equalTo($blocks[0]))->will($this->returnValue($blockInstance1));
$this->layoutMock->expects($this->at(1))->method('getBlock')->with($this->equalTo($blocks[1]))->will($this->returnValue($blockInstance2));
$this->translateInline->expects($this->once())->method('processResponseBody')->with($expectedData)->willReturnSelf();
$this->responseMock->expects($this->once())->method('appendBody')->with($this->equalTo(json_encode($expectedData)));
$this->action->execute();
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:26,代码来源:RenderTest.php
注:本文中的Magento\Framework\App\Response\Http类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论