本文整理汇总了PHP中Magento\Framework\App\ResponseInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface类的具体用法?PHP ResponseInterface怎么用?PHP ResponseInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResponseInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: aroundDispatch
/**
* Dispatch request
*
* @param \Magento\Framework\App\Action\Action $subject
* @param callable $proceed
* @param \Magento\Framework\App\RequestInterface $request
* @return \Magento\Framework\App\ResponseInterface
*/
public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
{
if (!$this->_appState->isInstalled()) {
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->_response->setRedirect($this->_url->getUrl('install'));
return $this->_response;
}
return $proceed($request);
}
示例2: downloadFileOption
/**
* Fetches and outputs file to user browser
* $info is array with following indexes:
* - 'path' - full file path
* - 'type' - mime type of file
* - 'size' - size of file
* - 'title' - user-friendly name of file (usually - original name as uploaded in Magento)
*
* @param \Magento\Framework\App\ResponseInterface $response
* @param string $filePath
* @param array $info
* @return bool
*/
public function downloadFileOption($response, $filePath, $info)
{
try {
$response->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $info['type'], true)->setHeader('Content-Length', $info['size'])->setHeader('Content-Disposition', 'inline' . '; filename=' . $info['title'])->clearBody();
$response->sendHeaders();
echo $this->directory->readFile($this->directory->getRelativePath($filePath));
} catch (\Exception $e) {
return false;
}
return true;
}
示例3: applyHttpHeaders
/**
* @param ResponseInterface $response
* @return $this
*/
protected function applyHttpHeaders(ResponseInterface $response)
{
if (!empty($this->httpResponseCode)) {
$response->setHttpResponseCode($this->httpResponseCode);
}
if ($this->statusHeaderCode) {
$response->setStatusHeader($this->statusHeaderCode, $this->statusHeaderVersion, $this->statusHeaderPhrase);
}
if (!empty($this->headers)) {
foreach ($this->headers as $headerData) {
$response->setHeader($headerData['name'], $headerData['value'], $headerData['replace']);
}
}
return $this;
}
示例4: setUp
/**
* Prepare required values
*
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function setUp()
{
$this->_request = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
$this->_response = $this->getMockBuilder('Magento\\Framework\\App\\Response\\Http')->disableOriginalConstructor()->setMethods(array('setRedirect', 'getHeader'))->getMock();
$this->_response->expects($this->any())->method('getHeader')->with($this->equalTo('X-Frame-Options'))->will($this->returnValue(true));
$this->_objectManager = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager')->disableOriginalConstructor()->setMethods(array('get', 'create'))->getMock();
$frontControllerMock = $this->getMockBuilder('Magento\\Framework\\App\\FrontController')->disableOriginalConstructor()->getMock();
$actionFlagMock = $this->getMockBuilder('Magento\\Framework\\App\\ActionFlag')->disableOriginalConstructor()->getMock();
$this->_session = $this->getMockBuilder('Magento\\Backend\\Model\\Session')->disableOriginalConstructor()->setMethods(array('setIsUrlNotice', '__wakeup'))->getMock();
$this->_session->expects($this->any())->method('setIsUrlNotice');
$this->_helper = $this->getMockBuilder('Magento\\Backend\\Helper\\Data')->disableOriginalConstructor()->setMethods(array('getUrl'))->getMock();
$this->messageManager = $this->getMockBuilder('Magento\\Framework\\Message\\Manager')->disableOriginalConstructor()->setMethods(array('addSuccess', 'addMessage', 'addException'))->getMock();
$contextArgs = array('getHelper', 'getSession', 'getAuthorization', 'getTranslator', 'getObjectManager', 'getFrontController', 'getActionFlag', 'getMessageManager', 'getLayoutFactory', 'getEventManager', 'getRequest', 'getResponse', 'getTitle', 'getView');
$contextMock = $this->getMockBuilder('\\Magento\\Backend\\App\\Action\\Context')->disableOriginalConstructor()->setMethods($contextArgs)->getMock();
$contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->_request));
$contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->_response));
$contextMock->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->_objectManager));
$contextMock->expects($this->any())->method('getFrontController')->will($this->returnValue($frontControllerMock));
$contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlagMock));
$contextMock->expects($this->any())->method('getHelper')->will($this->returnValue($this->_helper));
$contextMock->expects($this->any())->method('getSession')->will($this->returnValue($this->_session));
$contextMock->expects($this->any())->method('getMessageManager')->will($this->returnValue($this->messageManager));
$titleMock = $this->getMockBuilder('\\Magento\\Framework\\App\\Action\\Title')->getMock();
$contextMock->expects($this->any())->method('getTitle')->will($this->returnValue($titleMock));
$viewMock = $this->getMockBuilder('\\Magento\\Framework\\App\\ViewInterface')->getMock();
$viewMock->expects($this->any())->method('loadLayout')->will($this->returnSelf());
$contextMock->expects($this->any())->method('getView')->will($this->returnValue($viewMock));
$this->_acctServiceMock = $this->getMockBuilder('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface')->getMock();
$args = array('context' => $contextMock, 'accountService' => $this->_acctServiceMock);
$helperObjectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
$this->_testedObject = $helperObjectManager->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Newsletter', $args);
}
示例5: testRender
public function testRender()
{
$content = '<content>test</content>';
$this->raw->setContents($content);
$this->response->expects($this->once())->method('setBody')->with($content);
$this->assertSame($this->raw, $this->raw->renderResult($this->response));
}
示例6: testExecuteEmptyQuery
public function testExecuteEmptyQuery()
{
$searchString = "";
$this->request->expects($this->once())->method('getParam')->with('q')->will($this->returnValue($searchString));
$this->url->expects($this->once())->method('getBaseUrl');
$this->response->expects($this->once())->method('setRedirect');
$this->controller->execute();
}
示例7: testIndexActionException
public function testIndexActionException()
{
$this->request->expects($this->once())->method('isPost')->will($this->returnValue(true));
$exception = new \Exception();
$this->request->expects($this->once())->method('getPostValue')->will($this->throwException($exception));
$this->logger->expects($this->once())->method('critical')->with($this->identicalTo($exception));
$this->response->expects($this->once())->method('setHttpResponseCode')->with(500);
$this->model->executeInternal();
}
示例8: execute
/**
* Log out user and redirect him to new admin custom url
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.ExitExpression)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->_coreRegistry->registry('custom_admin_path_redirect') === null) {
return;
}
$this->_authSession->destroy();
$route = $this->_backendData->getAreaFrontName();
$this->_response->setRedirect($this->_storeManager->getStore()->getBaseUrl() . $route)->sendResponse();
exit(0);
}
示例9: execute
/**
* Log out user and redirect to new admin custom url
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.ExitExpression)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->_coreRegistry->registry('custom_admin_path_redirect') === null) {
return;
}
$this->_authSession->destroy();
$adminUrl = $this->_backendData->getHomePageUrl();
$this->_response->setRedirect($adminUrl)->sendResponse();
exit(0);
}
示例10: testExecuteRandom
public function testExecuteRandom()
{
$newKey = 'RSASHA9000VERYSECURESUPERMANKEY';
$this->requestMock->expects($this->at(0))->method('getPost')->with($this->equalTo('generate_random'))->willReturn(1);
$this->changeMock->expects($this->once())->method('changeEncryptionKey')->willReturn($newKey);
$this->managerMock->expects($this->once())->method('addSuccessMessage');
$this->managerMock->expects($this->once())->method('addNoticeMessage');
$this->cacheMock->expects($this->once())->method('clean');
$this->responseMock->expects($this->once())->method('setRedirect');
$this->model->execute();
}
示例11: testExecuteWithException
public function testExecuteWithException()
{
$this->requestMock->expects($this->once())->method('getParam')->with('item_id', null)->willReturn('1');
$exception = new \Exception('Error message!');
$this->sidebarMock->expects($this->once())->method('checkQuoteItem')->with(1)->willThrowException($exception);
$this->loggerMock->expects($this->once())->method('critical')->with($exception)->willReturn(null);
$this->sidebarMock->expects($this->once())->method('getResponseData')->with('Error message!')->willReturn(['success' => false, 'error_message' => 'Error message!']);
$this->jsonHelperMock->expects($this->once())->method('jsonEncode')->with(['success' => false, 'error_message' => 'Error message!'])->willReturn('json encoded');
$this->responseMock->expects($this->once())->method('representJson')->with('json encoded')->willReturn('json represented');
$this->assertEquals('json represented', $this->removeItem->executeInternal());
}
示例12: testExecute
public function testExecute()
{
$layout = $this->getMock('\\Magento\\Framework\\View\\LayoutInterface');
$block = $this->getMockBuilder('Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Bundle\\Option\\Search\\Grid')->disableOriginalConstructor()->setMethods(['setIndex', 'toHtml'])->getMock();
$this->response->expects($this->once())->method('setBody')->willReturnSelf();
$this->request->expects($this->once())->method('getParam')->with('index')->willReturn('index');
$this->view->expects($this->once())->method('getLayout')->willReturn($layout);
$layout->expects($this->once())->method('createBlock')->willReturn($block);
$block->expects($this->once())->method('setIndex')->willReturnSelf();
$block->expects($this->once())->method('toHtml')->willReturnSelf();
$this->assertEquals($this->response, $this->controller->execute());
}
示例13: testExecute
/**
* @return void
*/
public function testExecute()
{
$successMessage = 'All other open sessions for this account were terminated.';
$this->sessionsManager->expects($this->once())->method('logoutOtherUserSessions');
$this->messageManager->expects($this->once())->method('addSuccess')->with($successMessage);
$this->messageManager->expects($this->never())->method('addError');
$this->messageManager->expects($this->never())->method('addException');
$this->responseMock->expects($this->once())->method('setRedirect');
$this->actionFlagMock->expects($this->once())->method('get')->with('', \Magento\Backend\App\AbstractAction::FLAG_IS_URLS_CHECKED);
$this->backendHelperMock->expects($this->once())->method('getUrl');
$this->controller->execute();
}
示例14: testExecute
public function testExecute()
{
$type = 'sampleType';
$feed = $this->getMockBuilder('Magento\\SampleServiceContractNew\\API\\Data\\FeedInterface')->getMockForAbstractClass();
$xml = 'xmlDataString';
$this->request->expects($this->once())->method('getParam')->with('type')->willReturn($type);
$this->feedRepository->expects($this->once())->method('getById')->with($type)->willReturn($feed);
$this->response->expects($this->once())->method('setHeader')->with('Content-type', 'text/xml; charset=UTF-8')->willReturnSelf();
$this->feedTransformer->expects($this->once())->method('toXml')->with($feed)->willReturn($xml);
$this->response->expects($this->once())->method('setBody')->with($xml)->willReturnSelf();
$this->controller->execute();
}
示例15: testExecute
public function testExecute()
{
$product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getId'])->getMock();
$layout = $this->getMock('\\Magento\\Framework\\View\\LayoutInterface');
$block = $this->getMockBuilder('Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Bundle')->disableOriginalConstructor()->setMethods(['setIndex', 'toHtml'])->getMock();
$this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product);
$this->initializationHelper->expects($this->any())->method('initialize')->willReturn($product);
$this->response->expects($this->once())->method('setBody')->willReturnSelf();
$this->view->expects($this->once())->method('getLayout')->willReturn($layout);
$layout->expects($this->once())->method('createBlock')->willReturn($block);
$block->expects($this->once())->method('toHtml')->willReturnSelf();
$this->controller->execute();
}