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


PHP Response\Http类代码示例

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


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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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