Exemplo n.º 1
0
 /**
  * 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]);
 }
Exemplo n.º 2
0
 /**
  * Validate and Match /frontName- actionPath-action and converts them to: /frontName/actionPath/action
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     $info = $request->getPathInfo();
     if (preg_match("%^/(.*?)-(.*?)-(.*?)\$%", $info, $m)) {
         $request->setPathInfo(sprintf("/%s/%s/%s", $m[1], $m[2], $m[3]));
         return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
     }
     return null;
 }
Exemplo n.º 3
0
 /**
  * Modify request and set to no-route action
  *
  * @param RequestInterface $request
  * @return boolean
  */
 public function match(RequestInterface $request)
 {
     foreach ($this->noRouteHandlerList->getHandlers() as $noRouteHandler) {
         if ($noRouteHandler->process($request)) {
             break;
         }
     }
     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward');
 }
Exemplo n.º 4
0
 /**
  * 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');
 }
Exemplo n.º 5
0
 /**
  * {@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;
 }
Exemplo n.º 6
0
 /**
  * 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]);
 }
Exemplo n.º 7
0
 /**
  * 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');
 }
Exemplo n.º 8
0
 /**
  * @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');
 }
Exemplo n.º 9
0
 /**
  * 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');
 }
Exemplo n.º 10
0
 /**
  * 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));
 }
Exemplo n.º 11
0
 /**
  * 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]);
 }
Exemplo n.º 12
0
 /**
  * Validate and Match
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     $identifier = trim($request->getPathInfo(), '/');
     $identifier = strtolower($identifier);
     if (strpos($identifier, 'raacustomer') !== false) {
         /*
          * We must set module, controller path and action name for our controller class(Controller/Test/Test.php)
          */
         $request->setModuleName('raanalytics')->setControllerName('index')->setActionName('raacustomer');
     } else {
         if (strpos($identifier, 'raaproduct') !== false) {
             $request->setModuleName('raanalytics')->setControllerName('index')->setActionName('raaproduct');
         } else {
             if (strpos($identifier, 'raaproductbydate') !== false) {
                 $request->setModuleName('raanalytics')->setControllerName('index')->setActionName('raaproductbydate');
             } else {
                 if (strpos($identifier, 'raaproductcategory') !== false) {
                     $request->setModuleName('raanalytics')->setControllerName('index')->setActionName('raaproductcategory');
                 } else {
                     if (strpos($identifier, 'raaproductfinalprice') !== false) {
                         $request->setModuleName('raanalytics')->setControllerName('index')->setActionName('raaproductfinalprice');
                     } else {
                         if (strpos($identifier, 'raaorder') !== false) {
                             $request->setModuleName('raanalytics')->setControllerName('index')->setActionName('raaorder');
                         } else {
                             if (strpos($identifier, 'raaorderbydate') !== false) {
                                 $request->setModuleName('raanalytics')->setControllerName('index')->setActionName('raaorderbydate');
                             } else {
                                 if (strpos($identifier, 'raanalytics') !== false) {
                                     $request->setModuleName('raanalytics')->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]);
 }
Exemplo n.º 13
0
 /**
  * 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));
 }
Exemplo n.º 14
0
 /**
  * {@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;
 }
Exemplo n.º 15
0
 /**
  * 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;
 }
Exemplo n.º 16
0
 public function testMatch()
 {
     $this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store));
     $urlRewrite = $this->getMockBuilder('Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewrite')->disableOriginalConstructor()->getMock();
     $urlRewrite->expects($this->any())->method('getRedirectType')->will($this->returnValue(0));
     $urlRewrite->expects($this->any())->method('getTargetPath')->will($this->returnValue('target-path'));
     $this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue($urlRewrite));
     $this->request->expects($this->once())->method('setPathInfo')->with('/target-path');
     $this->actionFactory->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Action\\Forward', ['request' => $this->request]);
     $this->router->match($this->request);
 }
Exemplo n.º 17
0
 /**
  * Create matched controller instance
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @param array $params
  * @return \Magento\Framework\App\Action\Action|null
  */
 protected function matchAction(\Magento\Framework\App\RequestInterface $request, array $params)
 {
     $moduleFrontName = $this->matchModuleFrontName($request, $params['moduleFrontName']);
     if (empty($moduleFrontName)) {
         return null;
     }
     /**
      * Searching router args by module name from route using it as key
      */
     $modules = $this->_routeConfig->getModulesByFrontName($moduleFrontName);
     if (empty($modules) === true) {
         return null;
     }
     /**
      * Going through modules to find appropriate controller
      */
     $currentModuleName = null;
     $actionPath = null;
     $action = null;
     $actionInstance = null;
     $request->setRouteName($this->_routeConfig->getRouteByFrontName($moduleFrontName));
     $actionPath = $this->matchActionPath($request, $params['actionPath']);
     $action = $request->getActionName() ?: ($params['actionName'] ?: $this->_defaultPath->getPart('action'));
     $this->_checkShouldBeSecure($request, '/' . $moduleFrontName . '/' . $actionPath . '/' . $action);
     foreach ($modules as $moduleName) {
         $currentModuleName = $moduleName;
         $actionClassName = $this->actionList->get($moduleName, $this->pathPrefix, $actionPath, $action);
         if (!$actionClassName || !is_subclass_of($actionClassName, $this->actionInterface)) {
             continue;
         }
         $actionInstance = $this->actionFactory->create($actionClassName, array('request' => $request));
         break;
     }
     if (null == $actionInstance) {
         $actionInstance = $this->getNotFoundAction($currentModuleName, $request);
         if (is_null($actionInstance)) {
             return null;
         }
         $action = 'noroute';
     }
     // set values only after all the checks are done
     $request->setModuleName($moduleFrontName);
     $request->setControllerName($actionPath);
     $request->setActionName($action);
     $request->setControllerModule($currentModuleName);
     if (isset($params['variables'])) {
         $request->setParams($params['variables']);
     }
     return $actionInstance;
 }
Exemplo n.º 18
0
 public function testMatchEmptyActionInstance()
 {
     // Test Data
     $nullActionInstance = null;
     $moduleFrontName = 'module front name';
     $actionPath = 'action path';
     $actionName = 'action name';
     $actionClassName = 'Magento\\Cms\\Controller\\Index\\Index';
     $moduleName = 'module name';
     $moduleList = [$moduleName];
     // Stubs
     $this->requestMock->expects($this->any())->method('getModuleName')->willReturn($moduleFrontName);
     $this->routeConfigMock->expects($this->any())->method('getModulesByFrontName')->willReturn($moduleList);
     $this->requestMock->expects($this->any())->method('getControllerName')->willReturn($actionPath);
     $this->requestMock->expects($this->any())->method('getActionName')->willReturn($actionName);
     $this->appStateMock->expects($this->any())->method('isInstalled')->willReturn(false);
     $this->actionListMock->expects($this->any())->method('get')->willReturn($actionClassName);
     $this->actionFactoryMock->expects($this->any())->method('create')->willReturn($nullActionInstance);
     // Expectations and Test
     $this->assertNull($this->model->match($this->requestMock));
 }
Exemplo n.º 19
0
 /**
  * @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]);
             }
         }
     }
 }
Exemplo n.º 20
0
 /**
  * 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]);
 }
Exemplo n.º 21
0
 /**
  * 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');
                 }
             }
         }
     }
 }