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


PHP RequestInterface::setPathInfo方法代码示例

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


在下文中一共展示了RequestInterface::setPathInfo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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');
     }
 }
开发者ID:andrew-smart,项目名称:magento2-sample-module,代码行数:8,代码来源:Router.php

示例2: 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;
 }
开发者ID:Balfin,项目名称:m2test,代码行数:15,代码来源:Router.php

示例3: match

 /**
  * Validate and Match Cms Page and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return mixed
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     $identifier = trim($request->getPathInfo(), '/');
     $urlRewrite = $this->urlMatcher->match($identifier, $this->storeManager->getStore()->getId());
     if ($urlRewrite === null) {
         return null;
     }
     $redirectType = $urlRewrite->getRedirectType();
     if ($redirectType) {
         $redirectCode = $redirectType == \Magento\UrlRedirect\Model\OptionProvider::PERMANENT ? 301 : 302;
         $this->response->setRedirect($urlRewrite->getTargetPath(), $redirectCode);
         $request->setDispatched(true);
         return $this->actionFactory->createController('Magento\\Framework\\App\\Action\\Redirect', array('request' => $request));
     }
     $request->setPathInfo('/' . $urlRewrite->getTargetPath());
     return $this->actionFactory->createController('Magento\\Framework\\App\\Action\\Forward', array('request' => $request));
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:23,代码来源:Router.php

示例4: _prepareVdeRequest

 /**
  * Modify request path to imitate basic request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return $this
  */
 protected function _prepareVdeRequest(\Magento\Framework\App\RequestInterface $request)
 {
     list($vdeFrontName, $designMode, $themeId) = explode('/', trim($request->getPathInfo(), '/'));
     $request->setAlias('editorMode', $designMode);
     $request->setAlias('themeId', (int) $themeId);
     $vdePath = implode('/', array($vdeFrontName, $designMode, $themeId));
     $noVdePath = substr($request->getPathInfo(), strlen($vdePath) + 1) ?: '/';
     $request->setPathInfo($noVdePath);
     return $this;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:16,代码来源:Standard.php

示例5: 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)
 {
     $helper = $this->_helper;
     if ($helper->getBlogConfig('general/enabled')) {
         $url_prefix = $helper->getBlogConfig('general/url_prefix');
         $url_suffix = $helper->getBlogConfig('general/url_suffix');
         if ($url_prefix == '') {
             return $this;
         }
         $path = trim($request->getPathInfo(), '/');
         if (strpos($path, $url_prefix) === 0) {
             $array = explode('/', $path);
             if (count($array) == 1) {
                 $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                 $request->setPathInfo('/' . 'blog/post/index');
                 return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
             } elseif (count($array) == 2) {
                 $url_key = $array[1];
                 $post = $this->_helper->getPostByUrl($url_key);
                 if ($post && $post->getId()) {
                     $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $url_key);
                     $request->setPathInfo('/' . 'blog/post/view/id/' . $post->getId());
                     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                 }
             } elseif (count($array) == 3) {
                 $type = $array[1];
                 if ($type == 'post' && $array[2] == 'index') {
                     if ($array[2] == 'index') {
                         $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                         $request->setPathInfo('/' . 'blog/post/index');
                         return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                     } else {
                         $url_key = $array[2];
                         $post = $this->_helper->getPostByUrl($url_key);
                         if ($post && $post->getId()) {
                             $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $url_key);
                             $request->setPathInfo('/' . 'blog/post/view/id/' . $post->getId());
                             return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                         }
                     }
                 }
                 if ($type == 'post' && strpos($path, 'rss') !== false) {
                     $path = str_replace($url_prefix, 'blog', $path);
                     $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                     $request->setPathInfo($path);
                     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                 }
                 if ($type == 'topic') {
                     $topicUrlKey = $array[2];
                     $topic = $this->_helper->getTopicByParam('url_key', $topicUrlKey);
                     $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                     $request->setPathInfo('/' . 'blog/topic/view/id/' . $topic->getId());
                     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                 }
                 if ($type == 'tag') {
                     $tagUrlKey = $array[2];
                     $tag = $this->_helper->getTagByParam('url_key', $tagUrlKey);
                     $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                     $request->setPathInfo('/' . 'blog/tag/view/id/' . $tag->getId());
                     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                 }
                 if ($type == 'category') {
                     $categoryName = $array[2];
                     $category = $this->_helper->getCategoryByParam('url_key', $categoryName);
                     if ($category && $category->getId()) {
                         $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                         $request->setPathInfo('/' . 'blog/category/view/id/' . $category->getId());
                         return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                     }
                 }
             } elseif (count($array) > 3) {
                 if (strpos($path, 'rss') !== false) {
                     $path = str_replace($url_prefix, 'blog', $path);
                     $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $path);
                     $request->setPathInfo($path);
                     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
                 }
             }
         }
     }
 }
开发者ID:mageplaza,项目名称:magento-2-blog-extension,代码行数:87,代码来源:Router.php

示例6: rewrite

 /**
  * Perform custom url rewrites
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  */
 public function rewrite(\Magento\Framework\App\RequestInterface $request = null)
 {
     if (!$this->_appState->isInstalled()) {
         return false;
     }
     if (is_null($this->getStoreId()) || false === $this->getStoreId()) {
         $this->setStoreId($this->_storeManager->getStore()->getId());
     }
     /**
      * We have two cases of incoming paths - with and without slashes at the end ("/somepath/" and "/somepath").
      * Each of them matches two url rewrite request paths - with and without slashes at the end
      * ("/somepath/" and "/somepath").
      * Choose any matched rewrite, but in priority order that depends on same presence of slash and query params.
      */
     $requestCases = array();
     $pathInfo = $request->getPathInfo();
     $origSlash = substr($pathInfo, -1) == '/' ? '/' : '';
     $requestPath = trim($pathInfo, '/');
     // If there were final slash - add nothing to less priority paths. And vice versa.
     $altSlash = $origSlash ? '' : '/';
     $queryString = $this->_getQueryString();
     // Query params in request, matching "path + query" has more priority
     if ($queryString) {
         $requestCases[] = $requestPath . $origSlash . '?' . $queryString;
         $requestCases[] = $requestPath . $altSlash . '?' . $queryString;
     }
     $requestCases[] = $requestPath . $origSlash;
     $requestCases[] = $requestPath . $altSlash;
     $this->loadByRequestPath($requestCases);
     $targetUrl = $request->getBaseUrl();
     /**
      * Try to find rewrite by request path at first, if no luck - try to find by id_path
      */
     if (!$this->getId() && isset($_GET['___from_store'])) {
         try {
             $fromStoreId = $this->_storeManager->getStore($_GET['___from_store'])->getId();
         } catch (\Exception $e) {
             return false;
         }
         $this->setStoreId($fromStoreId)->loadByRequestPath($requestCases);
         if (!$this->getId()) {
             return false;
         }
         $currentStore = $this->_storeManager->getStore();
         $this->setStoreId($currentStore->getId())->loadByIdPath($this->getIdPath());
         $cookieMetadata = $this->_cookieMetadataFactory->createPublicCookieMetadata()->setDurationOneYear();
         $this->_cookieManager->setPublicCookie(\Magento\Store\Model\Store::COOKIE_NAME, $currentStore->getCode(), $cookieMetadata);
         $targetUrl .= '/' . $this->getRequestPath();
         $this->_sendRedirectHeaders($targetUrl, true);
     }
     if (!$this->getId()) {
         return false;
     }
     $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $this->getRequestPath());
     $external = substr($this->getTargetPath(), 0, 6);
     $isPermanentRedirectOption = $this->hasOption('RP');
     if ($external === 'http:/' || $external === 'https:') {
         $destinationStoreCode = $this->_storeManager->getStore($this->getStoreId())->getCode();
         $cookieMetadata = $this->_cookieMetadataFactory->createPublicCookieMetadata()->setDurationOneYear();
         $this->_cookieManager->setPublicCookie(\Magento\Store\Model\Store::COOKIE_NAME, $destinationStoreCode, $cookieMetadata);
         $this->_sendRedirectHeaders($this->getTargetPath(), $isPermanentRedirectOption);
     } else {
         $targetUrl .= '/' . $this->getTargetPath();
     }
     $isRedirectOption = $this->hasOption('R');
     $isStoreInUrl = $this->_scopeConfig->getValue(\Magento\Store\Model\Store::XML_PATH_STORE_IN_URL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($isRedirectOption || $isPermanentRedirectOption) {
         if ($isStoreInUrl && ($storeCode = $this->_storeManager->getStore()->getCode())) {
             $targetUrl .= '/' . $storeCode . '/' . $this->getTargetPath();
         }
         $this->_sendRedirectHeaders($targetUrl, $isPermanentRedirectOption);
     }
     if ($isStoreInUrl && ($storeCode = $this->_storeManager->getStore()->getCode())) {
         $targetUrl .= '/' . $storeCode . '/' . $this->getTargetPath();
     }
     $queryString = $this->_getQueryString();
     if ($queryString) {
         $targetUrl .= '?' . $queryString;
     }
     $request->setRequestUri($targetUrl);
     $request->setPathInfo($this->getTargetPath());
     return true;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:89,代码来源:UrlRewrite.php

示例7: 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 = trim($request->getPathInfo(), '/');
     //
     //         if(strpos($identifier, 'exampletocms') !== false) {
     //         return;
     //             /*
     //              * 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.
     //              */
     //             $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', 5);
     //         } else if(strpos($identifier, 'examplerouter') !== false) {
     //             /*
     //              * We must set module, controller path and action name for our controller class(Controller/Test/Test.php)
     //              */
     //             $request->setModuleName('shopbybrand')->setControllerName('view')->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]
     //         );
     $identifier = trim($request->getPathInfo(), '/');
     if (strpos($identifier, 'brand/view/index/id') !== false) {
         // called via id
         return null;
     } else {
         if (strpos($identifier, 'brand/') !== false) {
             $patharr = explode("/", $identifier);
             $urlpath = end($patharr);
             $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
             $modelcollection = $objectManager->get('\\Emizentech\\ShopByBrand\\Model\\BrandFactory')->create()->getCollection();
             $modelcollection->addFieldToFilter('url_key', $urlpath);
             if ($modelcollection->count() >= 1 && ($brand = $modelcollection->getFirstItem())) {
                 // 				var_dump($brand->debug());
                 $request->setModuleName('brand')->setControllerName('view')->setActionName('index')->setParam('id', $brand->getId());
                 $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier);
                 $request->setAlias(\Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS, '/' . $identifier);
                 $request->setPathInfo('/' . $identifier);
                 return;
             } else {
                 // not found any URL Key
                 return null;
             }
         } else {
             //There is no match
             return null;
         }
     }
 }
开发者ID:emizentech,项目名称:magento2-shop-by-brand,代码行数:67,代码来源:Router.php


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