本文整理汇总了PHP中Magento\Framework\App\ResponseInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ResponseInterface类的具体用法?PHP ResponseInterface怎么用?PHP ResponseInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResponseInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:aiesh,项目名称:magento2,代码行数:17,代码来源:Install.php
示例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;
}
开发者ID:aiesh,项目名称:magento2,代码行数:24,代码来源:Options.php
示例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;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:19,代码来源:AbstractResult.php
示例4: load
/**
* @param RequestInterface $request
* @param ResponseInterface $response
* @return bool
*/
public function load(RequestInterface $request, ResponseInterface $response)
{
$orderId = (int) $request->getParam('order_id');
if (!$orderId) {
$request->initForward();
$request->setActionName('noroute');
$request->setDispatched(false);
return false;
}
$order = $this->orderFactory->create()->load($orderId);
if ($this->orderAuthorization->canView($order)) {
$this->registry->register('current_order', $order);
return true;
}
$response->setRedirect($this->url->getUrl('*/*/history'));
return false;
}
开发者ID:aiesh,项目名称:magento2,代码行数:22,代码来源:OrderLoader.php
示例5: 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);
}
开发者ID:Atlis,项目名称:docker-magento2,代码行数:38,代码来源:NewsletterTest.php
示例6: 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));
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:7,代码来源:RawTest.php
示例7: 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();
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:8,代码来源:SuggestTest.php
示例8: 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();
}
开发者ID:nblair,项目名称:magescotch,代码行数:9,代码来源:IndexTest.php
示例9: 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);
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:17,代码来源:AfterCustomUrlChangedObserver.php
示例10: 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);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:18,代码来源:AfterCustomUrlChangedObserver.php
示例11: 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();
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:11,代码来源:SaveTest.php
示例12: 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());
}
开发者ID:nblair,项目名称:magescotch,代码行数:11,代码来源:RemoveItemTest.php
示例13: 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());
}
开发者ID:nja78,项目名称:magento2,代码行数:12,代码来源:GridTest.php
示例14: 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();
}
开发者ID:Doability,项目名称:magento2dev,代码行数:15,代码来源:LogoutAllTest.php
示例15: 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();
}
开发者ID:imbrj,项目名称:magento2-samples,代码行数:12,代码来源:ViewTest.php
示例16: 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();
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:13,代码来源:FormTest.php
示例17: match
/**
* Validate and Match Cms Page and modify request
*
* @param \Magento\Framework\App\RequestInterface $request
* @return bool
*
* @SuppressWarnings(PHPMD.ExitExpression)
*/
public function match(\Magento\Framework\App\RequestInterface $request)
{
if (!$this->_appState->isInstalled()) {
$this->_response->setRedirect($this->_url->getUrl('install'))->sendResponse();
exit;
}
$identifier = trim($request->getPathInfo(), '/');
$condition = new \Magento\Framework\Object(array('identifier' => $identifier, 'continue' => true));
$this->_eventManager->dispatch('cms_controller_router_match_before', array('router' => $this, 'condition' => $condition));
$identifier = $condition->getIdentifier();
if ($condition->getRedirectUrl()) {
$this->_response->setRedirect($condition->getRedirectUrl());
$request->setDispatched(true);
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', array('request' => $request));
}
if (!$condition->getContinue()) {
return null;
}
/** @var \Magento\Cms\Model\Page $page */
$page = $this->_pageFactory->create();
$pageId = $page->checkIdentifier($identifier, $this->_storeManager->getStore()->getId());
if (!$pageId) {
return null;
}
$request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', $pageId);
$request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier);
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', array('request' => $request));
}
开发者ID:aiesh,项目名称:magento2,代码行数:36,代码来源:Router.php
示例18: match
/**
* Validate and Match Blog Pages and modify request
*
* @param \Magento\Framework\App\RequestInterface $request
* @return bool
*/
public function match(\Magento\Framework\App\RequestInterface $request)
{
$_identifier = trim($request->getPathInfo(), '/');
if (strpos($_identifier, 'blog') !== 0) {
return;
}
$identifier = str_replace(array('blog/', 'blog'), '', $_identifier);
$condition = new \Magento\Framework\DataObject(['identifier' => $identifier, 'continue' => true]);
$this->_eventManager->dispatch('magefan_blog_controller_router_match_before', ['router' => $this, 'condition' => $condition]);
if ($condition->getRedirectUrl()) {
$this->_response->setRedirect($condition->getRedirectUrl());
$request->setDispatched(true);
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', ['request' => $request]);
}
if (!$condition->getContinue()) {
return null;
}
$identifier = $condition->getIdentifier();
$success = false;
$info = explode('/', $identifier);
if (!$identifier) {
$request->setModuleName('blog')->setControllerName('index')->setActionName('index');
$success = true;
} elseif (count($info) > 1) {
$store = $this->_storeManager->getStore()->getId();
switch ($info[0]) {
case 'post':
$post = $this->_postFactory->create();
$postId = $post->checkIdentifier($info[1], $this->_storeManager->getStore()->getId());
if (!$postId) {
return null;
}
$request->setModuleName('blog')->setControllerName('post')->setActionName('view')->setParam('id', $postId);
$success = true;
break;
case 'category':
$category = $this->_categoryFactory->create();
$categoryId = $category->checkIdentifier($info[1], $this->_storeManager->getStore()->getId());
if (!$categoryId) {
return null;
}
$request->setModuleName('blog')->setControllerName('category')->setActionName('view')->setParam('id', $categoryId);
$success = true;
break;
case 'archive':
$request->setModuleName('blog')->setControllerName('archive')->setActionName('view')->setParam('date', $info[1]);
$success = true;
break;
case 'search':
$request->setModuleName('blog')->setControllerName('search')->setActionName('index')->setParam('q', $info[1]);
$success = true;
break;
}
}
if (!$success) {
return null;
}
$request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $_identifier);
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
}
开发者ID:prachicis,项目名称:test_res,代码行数:66,代码来源:Router.php
示例19: testExecute
public function testExecute()
{
$firstElement = 'firstElement';
$symbolsDataArray = [$firstElement];
$redirectUrl = 'redirectUrl';
$this->requestMock->expects($this->once())->method('getParam')->with('custom_currency_symbol')->willReturn($symbolsDataArray);
$this->helperMock->expects($this->once())->method('getUrl')->with('*');
$this->redirectMock->expects($this->once())->method('getRedirectUrl')->willReturn($redirectUrl);
$this->currencySymbolMock->expects($this->once())->method('setCurrencySymbolsData')->with($symbolsDataArray);
$this->responseMock->expects($this->once())->method('setRedirect');
$this->filterManagerMock->expects($this->once())->method('stripTags')->with($firstElement)->willReturn($firstElement);
$this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\CurrencySymbol\\Model\\System\\Currencysymbol')->willReturn($this->currencySymbolMock);
$this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Framework\\Filter\\FilterManager')->willReturn($this->filterManagerMock);
$this->messageManagerMock->expects($this->once())->method('addSuccess')->with(__('You applied the custom currency symbols.'));
$this->action->execute();
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:SaveTest.php
示例20: testExecute
/**
* @param array $indexerIds
* @param \Exception $exception
* @param array $expectsExceptionValues
* @dataProvider executeDataProvider
*/
public function testExecute($indexerIds, $exception, $expectsExceptionValues)
{
$this->model = new \Magento\Indexer\Controller\Adminhtml\Indexer\MassChangelog($this->contextMock);
$this->request->expects($this->any())->method('getParam')->with('indexer_ids')->will($this->returnValue($indexerIds));
if (!is_array($indexerIds)) {
$this->messageManager->expects($this->once())->method('addError')->with(__('Please select indexers.'))->will($this->returnValue(1));
} else {
$this->objectManager->expects($this->any())->method('get')->with('Magento\\Framework\\Indexer\\IndexerRegistry')->will($this->returnValue($this->indexReg));
$indexerInterface = $this->getMockForAbstractClass('Magento\\Framework\\Indexer\\IndexerInterface', ['setScheduled'], '', false);
$this->indexReg->expects($this->any())->method('get')->with(1)->will($this->returnValue($indexerInterface));
if ($exception !== null) {
$indexerInterface->expects($this->any())->method('setScheduled')->with(true)->will($this->throwException($exception));
} else {
$indexerInterface->expects($this->any())->method('setScheduled')->with(true)->will($this->returnValue(1));
}
$this->messageManager->expects($this->any())->method('addSuccess')->will($this->returnValue(1));
if ($exception !== null) {
$this->messageManager->expects($this->exactly($expectsExceptionValues[2]))->method('addError')->with($exception->getMessage());
$this->messageManager->expects($this->exactly($expectsExceptionValues[1]))->method('addException')->with($exception, "We couldn't change indexer(s)' mode because of an error.");
}
}
$this->helper->expects($this->any())->method("getUrl")->willReturn("magento.com");
$this->response->expects($this->any())->method("setRedirect")->willReturn(1);
$this->model->executeInternal();
}
开发者ID:nblair,项目名称:magescotch,代码行数:31,代码来源:MassChangelogTest.php
注:本文中的Magento\Framework\App\ResponseInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论