本文整理汇总了PHP中Magento\Framework\App\RequestInterface类的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface类的具体用法?PHP RequestInterface怎么用?PHP RequestInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatch
/**
* Dispatch request
*
* @param RequestInterface $request
* @return ResponseInterface
* @throws NotFoundException
*/
public function dispatch(RequestInterface $request)
{
$this->_request = $request;
$profilerKey = 'CONTROLLER_ACTION:' . $request->getFullActionName();
$eventParameters = ['controller_action' => $this, 'request' => $request];
$this->_eventManager->dispatch('controller_action_predispatch', $eventParameters);
$this->_eventManager->dispatch('controller_action_predispatch_' . $request->getRouteName(), $eventParameters);
$this->_eventManager->dispatch('controller_action_predispatch_' . $request->getFullActionName(), $eventParameters);
\Magento\Framework\Profiler::start($profilerKey);
$result = null;
if ($request->isDispatched() && !$this->_actionFlag->get('', self::FLAG_NO_DISPATCH)) {
\Magento\Framework\Profiler::start('action_body');
$result = $this->execute();
\Magento\Framework\Profiler::start('postdispatch');
if (!$this->_actionFlag->get('', self::FLAG_NO_POST_DISPATCH)) {
$this->_eventManager->dispatch('controller_action_postdispatch_' . $request->getFullActionName(), $eventParameters);
$this->_eventManager->dispatch('controller_action_postdispatch_' . $request->getRouteName(), $eventParameters);
$this->_eventManager->dispatch('controller_action_postdispatch', $eventParameters);
}
\Magento\Framework\Profiler::stop('postdispatch');
\Magento\Framework\Profiler::stop('action_body');
}
\Magento\Framework\Profiler::stop($profilerKey);
return $result ?: $this->_response;
}
示例2: match
/**
* Validate and Match
*
* @param \Magento\Framework\App\RequestInterface $request
* @return bool
*/
public function match(\Magento\Framework\App\RequestInterface $request)
{
/*
* We will search “examplerouter” and “exampletocms” words and make forward depend on word
* -examplerouter will forward to base router to match inchootest front name, test controller path and test controller class
* -exampletocms will set front name to cms, controller path to page and action to view
*/
$identifier = explode('/', trim($request->getPathInfo(), '/'));
if (strpos($identifier[0], 'brands') !== false && isset($identifier[1])) {
/*
* We must set module, controller path and action name + we will set page id 5 witch is about us page on
* default magento 2 installation with sample data.
*/
$id = $this->_brandFactory->create()->getCollection()->addFieldToSelect('id')->addFieldToFilter('url_key', ['eq' => $identifier[1]])->addFieldToFilter('is_active', \Emizentech\ShopByBrand\Model\Status::STATUS_ENABLED)->getFirstItem()->getId();
if ($id) {
$request->setModuleName('brand')->setControllerName('view')->setActionName('index')->setParam('id', $id);
} else {
return;
}
} else {
if (strpos($identifier[0], 'brands') !== false) {
/*
* We must set module, controller path and action name for our controller class(Controller/Test/Test.php)
*/
$request->setModuleName('brand')->setControllerName('index')->setActionName('index');
} else {
//There is no match
return;
}
}
/*
* We have match and now we will forward action
*/
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
}
示例3: dispatch
/**
* Check if current section is found and is allowed
*
* @param \Magento\Framework\App\RequestInterface $request
* @return \Magento\Framework\App\ResponseInterface
*/
public function dispatch(\Magento\Framework\App\RequestInterface $request)
{
if (!$request->getParam('section')) {
$request->setParam('section', $this->_configStructure->getFirstSection()->getId());
}
return parent::dispatch($request);
}
示例4: __construct
/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param RequestInterface $request
* @param array $meta
* @param array $data
*/
public function __construct($name, $primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, RequestInterface $request, array $meta = [], array $data = [])
{
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->request = $request;
$this->collection = $collectionFactory->create();
$this->collection->setExcludeSetFilter((int) $this->request->getParam('template_id', 0));
}
示例5: _validateProductVariations
/**
* Product variations attributes validation
*
* @param Product $parentProduct
* @param array $products
* @param RequestInterface $request
* @return array
*/
protected function _validateProductVariations(Product $parentProduct, array $products, RequestInterface $request)
{
$this->eventManager->dispatch('catalog_product_validate_variations_before', ['product' => $parentProduct, 'variations' => $products]);
$validationResult = [];
foreach ($products as $productData) {
$product = $this->productFactory->create();
$product->setData('_edit_mode', true);
$storeId = $request->getParam('store');
if ($storeId) {
$product->setStoreId($storeId);
}
$product->setAttributeSetId($parentProduct->getAttributeSetId());
$product->addData($this->getRequiredDataFromProduct($parentProduct));
$product->addData($productData);
$product->setCollectExceptionMessages(true);
$configurableAttribute = [];
$encodedData = $productData['configurable_attribute'];
if ($encodedData) {
$configurableAttribute = $this->jsonHelper->jsonDecode($encodedData);
}
$configurableAttribute = implode('-', $configurableAttribute);
$errorAttributes = $product->validate();
if (is_array($errorAttributes)) {
foreach ($errorAttributes as $attributeCode => $result) {
if (is_string($result)) {
$key = 'variations-matrix-' . $configurableAttribute . '-' . $attributeCode;
$validationResult[$key] = $result;
}
}
}
}
return $validationResult;
}
示例6: 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);
}
}
示例7: afterGenerateXml
/**
* After generate Xml
*
* @param \Magento\Framework\View\LayoutInterface $subject
* @param \Magento\Framework\View\LayoutInterface $result
* @return \Magento\Framework\View\LayoutInterface
*/
public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
{
if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) {
$this->checkoutSession->clearStorage();
}
return $result;
}
示例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);
}
示例9: afterInitialize
/**
* Setting Bundle Items Data to product for further processing
*
* @param \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $subject
* @param \Magento\Catalog\Model\Product $product
*
* @return \Magento\Catalog\Model\Product
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function afterInitialize(\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper $subject, \Magento\Catalog\Model\Product $product)
{
$compositeReadonly = $product->getCompositeReadonly();
$result['bundle_selections'] = $result['bundle_options'] = [];
if (isset($this->request->getPost('bundle_options')['bundle_options'])) {
foreach ($this->request->getPost('bundle_options')['bundle_options'] as $key => $option) {
if (empty($option['bundle_selections'])) {
continue;
}
$result['bundle_selections'][$key] = $option['bundle_selections'];
unset($option['bundle_selections']);
$result['bundle_options'][$key] = $option;
}
if ($result['bundle_selections'] && !$compositeReadonly) {
$product->setBundleSelectionsData($result['bundle_selections']);
}
if ($result['bundle_options'] && !$compositeReadonly) {
$product->setBundleOptionsData($result['bundle_options']);
}
$this->processBundleOptionsData($product);
$this->processDynamicOptionsData($product);
}
$affectProductSelections = (bool) $this->request->getPost('affect_bundle_product_selections');
$product->setCanSaveBundleSelections($affectProductSelections && !$compositeReadonly);
return $product;
}
示例10: testExecute
public function testExecute()
{
$this->request->expects($this->once())
->method('isPost')
->willReturn(true);
$this->request->expects($this->once())
->method('getParam')
->with('files')
->willReturn('{"files":"file"}');
$jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false);
$jsonData->expects($this->once())
->method('jsonDecode')
->with('{"files":"file"}')
->willReturn(['files' => 'file']);
$this->objectManager->expects($this->at(0))
->method('get')
->with('Magento\Framework\Json\Helper\Data')
->willReturn($jsonData);
$this->objectManager->expects($this->at(1))
->method('get')
->with('Magento\Theme\Model\Wysiwyg\Storage')
->willReturn($this->storage);
$this->storage->expects($this->once())
->method('deleteFile')
->with('file');
$this->controller->executeInternal();
}
示例11: testGetCollection
public function testGetCollection()
{
$this->collectionMock->expects($this->once())->method('addAttributeToFilter');
$this->productLinkRepositoryMock->expects($this->once())->method('getList')->willReturn([]);
$this->requestMock->expects($this->exactly(2))->method('getParam')->willReturn(1);
$this->assertInstanceOf(Collection::class, $this->getModel()->getCollection());
}
示例12: testGetAction
/**
* @param bool $isSecure
* @param string $actionUrl
* @param int $productId
* @dataProvider getActionDataProvider
*/
public function testGetAction($isSecure, $actionUrl, $productId)
{
$this->urlBuilder->expects($this->any())->method('getUrl')->with('review/product/post', ['_secure' => $isSecure, 'id' => $productId])->willReturn($actionUrl . '/id/' . $productId);
$this->requestMock->expects($this->any())->method('getParam')->with('id', false)->willReturn($productId);
$this->requestMock->expects($this->any())->method('isSecure')->willReturn($isSecure);
$this->assertEquals($actionUrl . '/id/' . $productId, $this->object->getAction());
}
示例13: testGetDistroBaseUrl
/**
* @param $serverVariables array
* @param $expectedResult string
* @dataProvider serverVariablesProvider
*/
public function testGetDistroBaseUrl($serverVariables, $expectedResult)
{
$originalServerValue = $_SERVER;
$_SERVER = $serverVariables;
$this->assertEquals($expectedResult, $this->_model->getDistroBaseUrl());
$_SERVER = $originalServerValue;
}
示例14: getLinks
/**
* Get stored value.
* Fallback to request if none.
*
* @return array|null
*/
public function getLinks()
{
if (null === $this->links) {
$this->links = (array) $this->request->getParam('links', []);
}
return $this->links;
}
示例15: getData
/**
* Retrieve configuration metadata
*
* @return array
*/
public function getData()
{
$scope = $this->request->getParam('scope');
$scopeId = $this->request->getParam('scope_id');
$data = [];
if ($scope) {
$showFallbackReset = false;
list($fallbackScope, $fallbackScopeId) = $this->scopeFallbackResolver->getFallbackScope($scope, $scopeId);
if ($fallbackScope && !$this->storeManager->isSingleStoreMode()) {
$scope = $fallbackScope;
$scopeId = $fallbackScopeId;
$showFallbackReset = true;
}
$designConfig = $this->designConfigRepository->getByScope($scope, $scopeId);
$fieldsData = $designConfig->getExtensionAttributes()->getDesignConfigData();
foreach ($fieldsData as $fieldData) {
$element =& $data;
foreach (explode('/', $fieldData->getFieldConfig()['fieldset']) as $fieldset) {
if (!isset($element[$fieldset]['children'])) {
$element[$fieldset]['children'] = [];
}
$element =& $element[$fieldset]['children'];
}
$fieldName = $fieldData->getFieldConfig()['field'];
$element[$fieldName]['arguments']['data']['config']['default'] = $fieldData->getValue();
$element[$fieldName]['arguments']['data']['config']['showFallbackReset'] = $showFallbackReset;
}
}
return $data;
}