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


PHP RequestInterface::setAlias方法代码示例

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


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

示例1: 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]);
 }
开发者ID:pyvil,项目名称:magento2-blog-module,代码行数:21,代码来源:Router.php

示例2: 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');
 }
开发者ID:luxwan13,项目名称:magento2-learning,代码行数:20,代码来源:Router.php

示例3: 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');
 }
开发者ID:PeterReuleke,项目名称:module-news,代码行数:20,代码来源:Router.php

示例4: 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');
 }
开发者ID:V3N0m21,项目名称:test-example,代码行数:18,代码来源:Router.php

示例5: 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');
 }
开发者ID:swnsma,项目名称:practice,代码行数:21,代码来源:Router.php

示例6: match

 /**
  * Validate and Match testimonials  and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     //        throw new \Magento\Framework\Exception\LocalizedException(
     //        __('$request->getPathInfo()  ' . $request->getPathInfo())
     //        );
     //        $url_key = trim($request->getPathInfo(), '/testimonials/');
     $url_key = str_replace('/testimonials/', '', $request->getPathInfo());
     $url_key = rtrim($url_key, '/');
     //        throw new \Magento\Framework\Exception\LocalizedException(
     //        __('$url_key  ' . $url_key)
     //        );
     /** @var \Test\Testimonials\Model\Post $post */
     $post = $this->_postFactory->create();
     $post_id = $post->checkUrlKey($url_key);
     if (!$post_id) {
         return null;
     }
     $request->setModuleName('testimonials')->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');
 }
开发者ID:antonsbox,项目名称:testimonials,代码行数:27,代码来源:Router.php

示例7: matchActionPath

 /**
  * Match controller name
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @param string $param
  * @return string
  */
 protected function matchActionPath(\Magento\Framework\App\RequestInterface $request, $param)
 {
     if ($request->getControllerName()) {
         $actionPath = $request->getControllerName();
     } elseif (!empty($param)) {
         $actionPath = $param;
     } else {
         $actionPath = $this->_defaultPath->getPart('controller');
         $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, ltrim($request->getOriginalPathInfo(), '/'));
     }
     return $actionPath;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:19,代码来源:Base.php

示例8: 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)
 {
     $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:pavelnovitsky,项目名称:magento2,代码行数:30,代码来源:Router.php

示例9: 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(RequestInterface $request)
 {
     if (!$this->dispatched) {
         $urlKey = trim($request->getPathInfo(), '/');
         $origUrlKey = $urlKey;
         /** @var Object $condition */
         $condition = new Object(['url_key' => $urlKey, 'continue' => true]);
         $this->eventManager->dispatch('sample_news_controller_router_match_before', ['router' => $this, 'condition' => $condition]);
         $urlKey = $condition->getUrlKey();
         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;
         }
         $entities = ['author' => ['prefix' => $this->scopeConfig->getValue('sample_news/author/url_prefix', ScopeInterface::SCOPE_STORES), 'suffix' => $this->scopeConfig->getValue('sample_news/author/url_suffix', ScopeInterface::SCOPE_STORES), 'list_key' => $this->scopeConfig->getValue('sample_news/author/list_url', ScopeInterface::SCOPE_STORES), 'list_action' => 'index', 'factory' => $this->authorFactory, 'controller' => 'author', 'action' => 'view', 'param' => 'id']];
         foreach ($entities as $entity => $settings) {
             if ($settings['list_key']) {
                 if ($urlKey == $settings['list_key']) {
                     $request->setModuleName('sample_news')->setControllerName($settings['controller'])->setActionName($settings['list_action']);
                     $request->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $urlKey);
                     $this->dispatched = true;
                     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
                 }
             }
             if ($settings['prefix']) {
                 $parts = explode('/', $urlKey);
                 if ($parts[0] != $settings['prefix'] || count($parts) != 2) {
                     continue;
                 }
                 $urlKey = $parts[1];
             }
             if ($settings['suffix']) {
                 $suffix = substr($urlKey, -strlen($settings['suffix']) - 1);
                 if ($suffix != '.' . $settings['suffix']) {
                     continue;
                 }
                 $urlKey = substr($urlKey, 0, -strlen($settings['suffix']) - 1);
             }
             /** @var \Sample\News\Model\Author $instance */
             $instance = $settings['factory']->create();
             $id = $instance->checkUrlKey($urlKey, $this->storeManager->getStore()->getId());
             if (!$id) {
                 return null;
             }
             $request->setModuleName('sample_news')->setControllerName('author')->setActionName('view')->setParam('id', $id);
             $request->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $origUrlKey);
             $request->setDispatched(true);
             $this->dispatched = true;
             return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
         }
     }
     return null;
 }
开发者ID:nhc,项目名称:Magento2SampleModule,代码行数:62,代码来源:Router.php

示例10: _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

示例11: 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(), '/');
     $pathInfo = explode('/', $_identifier);
     $blogRoute = $this->_url->getRoute();
     if ($pathInfo[0] != $blogRoute) {
         return;
     }
     unset($pathInfo[0]);
     switch ($this->_url->getPermalinkType()) {
         case Url::PERMALINK_TYPE_DEFAULT:
             foreach ($pathInfo as $i => $route) {
                 $pathInfo[$i] = $this->_url->getControllerName($route);
             }
             break;
         case Url::PERMALINK_TYPE_SHORT:
             if ($pathInfo[1] == $this->_url->getRoute(Url::CONTROLLER_SEARCH)) {
                 $pathInfo[1] = Url::CONTROLLER_SEARCH;
             } elseif (count($pathInfo) == 1) {
                 if ($this->_isArchiveIdentifier($pathInfo[1])) {
                     $pathInfo[2] = $pathInfo[1];
                     $pathInfo[1] = Url::CONTROLLER_ARCHIVE;
                 } elseif ($postId = $this->_getPostId($pathInfo[1])) {
                     $pathInfo[2] = $pathInfo[1];
                     $pathInfo[1] = Url::CONTROLLER_POST;
                 } elseif ($categoryId = $this->_getCategoryId($pathInfo[1])) {
                     $pathInfo[2] = $pathInfo[1];
                     $pathInfo[1] = Url::CONTROLLER_CATEGORY;
                 }
             }
             break;
     }
     $identifier = implode('/', $pathInfo);
     $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':
                 if (!($postId = $this->_getPostId($info[1]))) {
                     return null;
                 }
                 $request->setModuleName('blog')->setControllerName('post')->setActionName('view')->setParam('id', $postId);
                 $success = true;
                 break;
             case 'category':
                 if (!($categoryId = $this->_getCategoryId($info[1]))) {
                     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;
             case 'rss':
                 $request->setModuleName('blog')->setControllerName('rss')->setActionName(isset($info[1]) ? $info[1] : 'index');
                 $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:Wojton,项目名称:Blog-Extension-for-Magento-2,代码行数:92,代码来源:Router.php

示例12: 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

示例13: 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

示例14: 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

示例15: match

 /**
  * @param RequestInterface $request
  * @return \Magento\Framework\App\ActionInterface
  */
 public function match(RequestInterface $request)
 {
     $_brandHelper = $this->_brandHelper;
     if (!$this->dispatched) {
         $urlKey = trim($request->getPathInfo(), '/');
         $origUrlKey = $urlKey;
         /** @var Object $condition */
         $condition = new DataObject(['url_key' => $urlKey, 'continue' => true]);
         $this->eventManager->dispatch('ves_brand_controller_router_match_before', ['router' => $this, 'condition' => $condition]);
         $urlKey = $condition->getUrlKey();
         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;
         }
         $route = $_brandHelper->getConfig('general_settings/route');
         if ($urlKey == $route) {
             $request->setModuleName('vesbrand')->setControllerName('index')->setActionName('index');
             $request->setAlias(Url::REWRITE_REQUEST_PATH_ALIAS, $urlKey);
             $this->dispatched = true;
             return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
         }
         $url_prefix = $_brandHelper->getConfig('general_settings/url_prefix');
         $url_suffix = $_brandHelper->getConfig('general_settings/url_suffix');
         $identifiers = explode('/', $urlKey);
         //Check Group Url
         if (count($identifiers) == 2 && $identifiers[0] == $url_prefix && strpos($identifiers[1], $url_suffix) || trim($url_prefix) == '' && count($identifiers) == 1) {
             $brandUrl = '';
             if (trim($url_prefix) == '' && count($identifiers) == 1) {
                 $brandUrl = str_replace($url_suffix, '', $identifiers[0]);
             }
             if (count($identifiers) == 2) {
                 $brandUrl = str_replace($url_suffix, '', $identifiers[1]);
             }
             $group = $this->_groupCollection->getCollection()->addFieldToFilter('status', array('eq' => 1))->addFieldToFilter('url_key', array('eq' => $brandUrl))->getFirstItem();
             if ($group && $group->getId()) {
                 $request->setModuleName('vesbrand')->setControllerName('group')->setActionName('view')->setParam('group_id', $group->getId());
                 $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $origUrlKey);
                 $request->setDispatched(true);
                 $this->dispatched = true;
                 return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
             }
         }
         // Check Brand Url Key
         if (count($identifiers) == 2 && $identifiers[0] == $url_prefix && strpos($identifiers[1], $url_suffix) || trim($url_prefix) == '' && count($identifiers) == 1) {
             if (count($identifiers) == 2) {
                 $brandUrl = str_replace($url_suffix, '', $identifiers[1]);
             }
             if (trim($url_prefix) == '' && count($identifiers) == 1) {
                 $brandUrl = str_replace($url_suffix, '', $identifiers[0]);
             }
             $brand = $this->_brandCollection->getCollection()->addFieldToFilter('status', array('eq' => 1))->addFieldToFilter('url_key', array('eq' => $brandUrl))->getFirstItem();
             if ($brand && $brand->getId() && (in_array($this->storeManager->getStore()->getId(), $brand->getStoreId()) || in_array(0, $brand->getStoreId()))) {
                 $request->setModuleName('vesbrand')->setControllerName('brand')->setActionName('view')->setParam('brand_id', $brand->getId());
                 $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $origUrlKey);
                 $request->setDispatched(true);
                 $this->dispatched = true;
                 return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
             }
         }
     }
 }
开发者ID:vasuscoin,项目名称:brand,代码行数:69,代码来源:Router.php


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