本文整理汇总了PHP中Magento\Framework\App\RequestInterface::getPathInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getPathInfo方法的具体用法?PHP RequestInterface::getPathInfo怎么用?PHP RequestInterface::getPathInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getPathInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeGetTargetStorePostData
/**
* Set redirect url for store view based on request path info
*
* @param \Magento\Store\Block\Switcher $switcher
* @param \Magento\Store\Model\Store $store
* @param array $data
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeGetTargetStorePostData(\Magento\Store\Block\Switcher $switcher, \Magento\Store\Model\Store $store, $data = [])
{
$urlRewrite = $this->urlFinder->findOneByData([UrlRewrite::TARGET_PATH => $this->trimSlashInPath($this->request->getPathInfo()), UrlRewrite::STORE_ID => $store->getId()]);
if ($urlRewrite) {
$data[ActionInterface::PARAM_NAME_URL_ENCODED] = $this->urlHelper->getEncodedUrl($this->trimSlashInPath($this->urlBuilder->getUrl($urlRewrite->getRequestPath())));
}
return [$store, $data];
}
示例2: match
/**
* {@inheritdoc}
*/
public function match(RequestInterface $request)
{
/** @var \Magento\Framework\App\Request\Http $request */
$identifier = trim($request->getPathInfo(), '/');
$this->eventManager->dispatch('core_controller_router_match_before', ['router' => $this, 'condition' => new DataObject(['identifier' => $identifier, 'continue' => true])]);
$pathInfo = $request->getPathInfo();
$result = $this->url->match($pathInfo);
if ($result) {
$params = $result->getParams();
$request->setModuleName($result->getModuleName())->setControllerName($result->getControllerName())->setActionName($result->getActionName())->setParams($params);
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
}
return false;
}
示例3: match
/**
* Validate and Match News Author and modify request
* @param \Magento\Framework\App\RequestInterface $request
* @return bool
* //TODO: maybe remove this and use the url rewrite table.
*/
public function match(\Magento\Framework\App\RequestInterface $request)
{
if (!$this->dispatched) {
$ipModel = $this->_ipFactory->create();
$ipCollection = $ipModel->getCollection();
$ip = $_SERVER['REMOTE_ADDR'];
// echo $ip;die;
$whitelists = $ipCollection->addFieldToFilter('member_access', 1)->addFieldToFilter('ip_address', $ip);
//Get Ip exist in whitelist
$arrayfilter = array_filter($whitelists->getData());
// Remove all empty values
if (empty($arrayfilter)) {
// check whether an array is empty or not
//echo "hello";die;
//foreach($whitelists as $ip){
//$whiteips[]=$ip->getIpAddress();
//}
//if (!in_array($ip, $whiteips)){
$identifier = trim($request->getPathInfo(), '/');
//echo $identifier;die;
// echo "wecome";die;
//echo $ip;die;
//if($ip=='172.17.0.1'){
//$request->setModuleName('firewall')->setControllerName('ipblock')->setActionName('ipblock');
$request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', 1);
$request->setDispatched(true);
$this->dispatched = true;
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
//}
}
return null;
}
return null;
}
示例4: 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]);
}
示例5: match
public function match(RequestInterface $request)
{
$match = preg_match('#^\\/example-custom-route-handler-([0-9]*)$#', $request->getPathInfo());
if ($match) {
$request->setPathInfo('/cms');
return $this->_actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
}
}
示例6: match
/**
* {@inheritdoc}
*/
public function match(RequestInterface $request)
{
/** @var \Magento\Framework\App\Request\Http $request */
$identifier = trim($request->getPathInfo(), '/');
$this->eventManager->dispatch('core_controller_router_match_before', ['router' => $this, 'condition' => new DataObject(['identifier' => $identifier, 'continue' => true])]);
$pathInfo = $request->getPathInfo();
$result = $this->urlRewrite->match($pathInfo);
if ($result) {
$params = [];
if ($result->getEntityId()) {
$params['id'] = $result->getEntityId();
}
$params = array_merge($params, $result->getActionParams());
$request->setModuleName($result->getModuleName())->setControllerName($result->getControllerName())->setActionName($result->getActionName())->setParams($params)->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $identifier);
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
}
return false;
}
示例7: match
/**
* use /test-action-config as a test url for example
*
* @param \Magento\Framework\App\RequestInterface $request
* @return \Magento\Framework\App\ActionInterface|null
*/
public function match(\Magento\Framework\App\RequestInterface $request)
{
$info = $request->getPathInfo();
if (preg_match("%^/(test)-(.*?)-(.*?)\$%", $info, $m)) {
$request->setPathInfo(sprintf("/%s/%s/%s", $m[1], $m[2], $m[3]));
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
}
return null;
}
示例8: process
/**
* Check and process no route request
*
* @param \Magento\Framework\App\RequestInterface $request
* @return bool
*/
public function process(\Magento\Framework\App\RequestInterface $request)
{
$requestPathParams = explode('/', trim($request->getPathInfo(), '/'));
$areaFrontName = array_shift($requestPathParams);
if ($areaFrontName == $this->helper->getAreaFrontName()) {
$moduleName = $this->routeConfig->getRouteFrontName('adminhtml');
$actionNamespace = 'noroute';
$actionName = 'index';
$request->setModuleName($moduleName)->setControllerName($actionNamespace)->setActionName($actionName);
return true;
}
return false;
}
示例9: match
/**
* Validate and Match Blog Post and modify request
*
* @param \Magento\Framework\App\RequestInterface $request
* @return bool
*/
public function match(\Magento\Framework\App\RequestInterface $request)
{
$url_key = trim($request->getPathInfo(), '/blog/');
$url_key = rtrim($url_key, '/');
/** @var \Ashsmith\Blog\Model\Post $post */
$post = $this->_postFactory->create();
$post_id = $post->checkUrlKey($url_key);
if (!$post_id) {
return null;
}
$request->setModuleName('blog')->setControllerName('view')->setActionName('index')->setParam('post_id', $post_id);
$request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $url_key);
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
}
示例10: match
/**
* Match application action by request
*
* @param RequestInterface $request
*
* @return ActionInterface
*/
public function match(RequestInterface $request)
{
$slug = trim($request->getPathInfo(), '/blog/');
$slug = rtrim($slug, '/');
/** @var \Pyvil\Blog\Model\Post $post */
$post = $this->_postFactory->create();
$postId = $post->checkSlug($slug);
if (!$postId) {
return null;
}
$request->setModuleName('blog')->setControllerName('view')->setActionName('index')->setParam('id', $postId);
$request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $slug);
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
}
示例11: match
/**
* Validate and Match Cms Page and modify request
*
* @param \Magento\Framework\App\RequestInterface $request
* @return bool
*/
public function match(\Magento\Framework\App\RequestInterface $request)
{
$url_key = trim($request->getPathInfo(), '/news/');
$url_key = rtrim($url_key, '/');
/** @var \Pre\News\Model\Feed $feed */
$feed = $this->_pageFactory->create();
$feed_id = $feed->checkUrlKey($url_key);
if (!$feed_id) {
return null;
}
$request->setModuleName('news')->setControllerName('view')->setActionName('index')->setParam('feed_id', $feed_id);
$request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $url_key);
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
}
示例12: match
/**
* @param \Magento\Framework\App\RequestInterface $request
* @return bool
*/
public function match(\Magento\Framework\App\RequestInterface $request)
{
$url_key = trim($request->getPathInfo(), '/testimonial/');
$url_key = rtrim($url_key, '/');
/** @var \V3N0m21\Testimonials\Model\Testimonial $testimonial */
$testimonial = $this->_testimonialFactory->create();
$testimonial_id = $testimonial->getById($url_key);
if (!$testimonial_id) {
return null;
}
$request->setModuleName('testimonials')->setControllerName('view')->setActionName('index')->setParam('testimonial_id', $testimonial_id);
$request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $url_key);
return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
}
示例13: match
/**
* Validate and Match Blog Post and modify request
*
* @param RequestInterface $request
* @return bool
*/
public function match(RequestInterface $request)
{
$urlKey = str_replace("/blog/", "", $request->getPathInfo());
$urlKey = rtrim($urlKey, '/');
$urlKey = ltrim($urlKey, '/');
/** @var \ISM\Blog\Model\Post $post */
$post = $this->_postFactory->create();
$id = $post->checkUrlKey($urlKey);
if (!$id) {
return null;
}
$request->setModuleName('blog')->setControllerName('view')->setActionName('index')->setParam('id', $id);
$request->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $urlKey);
return $this->_actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
}
示例14: process
/**
* Check and process no route request
*
* @param \Magento\Framework\App\RequestInterface $request
* @return bool
*/
public function process(\Magento\Framework\App\RequestInterface $request)
{
$pathInfo = $request->getPathInfo();
$parts = explode('/', trim($pathInfo, '/'));
$moduleName = isset($parts[0]) ? $parts[0] : '';
$actionPath = isset($parts[1]) ? $parts[1] : '';
$actionName = isset($parts[2]) ? $parts[2] : '';
if ($moduleName == 'catalog' && $actionPath == 'product' && $actionName == 'view') {
$request->setModuleName('specific404page')->setControllerName('noroute')->setActionName('product');
} elseif ($moduleName == 'catalog' && $actionPath == 'category' && $actionName == 'view') {
$request->setModuleName('specific404page')->setControllerName('noroute')->setActionName('category');
} else {
$request->setModuleName('specific404page')->setControllerName('noroute')->setActionName('other');
}
return true;
}
示例15: process
public function process(Request $request)
{
$path = $request->getPathInfo();
$arr = explode('/', trim($path, '/'));
$module = isset($arr[0]) ? $arr[0] : '';
$controller = isset($arr[1]) ? $arr[1] : '';
$action = isset($arr[2]) ? $arr[2] : '';
if ($module === 'catalog' && $controller == 'product' && $action == 'view') {
$request->setModuleName('customrouter')->setControllerName('router')->setActionName('product');
} elseif ($module === 'catalog' && $controller == 'category' && $action == 'view') {
$request->setModuleName('customrouter')->setControllerName('router')->setActionName('category');
} else {
$request->setModuleName('customrouter')->setControllerName('router')->setActionName('other');
}
return false;
}