Example #1
0
 /**
  * @param string $pathInfo
  * @return bool|DataObject
  */
 public function match($pathInfo)
 {
     $identifier = trim($pathInfo, '/');
     $parts = explode('/', $identifier);
     if (count($parts) >= 1) {
         $parts[count($parts) - 1] = $this->trimSuffix($parts[count($parts) - 1]);
     }
     if ($parts[0] != $this->config->getBaseRoute()) {
         return false;
     }
     if (count($parts) > 1) {
         unset($parts[0]);
         $parts = array_values($parts);
         $urlKey = implode('/', $parts);
         $urlKey = urldecode($urlKey);
         $urlKey = $this->trimSuffix($urlKey);
     } else {
         $urlKey = '';
     }
     if ($urlKey == '') {
         return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'index', 'params' => []]);
     }
     if ($parts[0] == 'search') {
         return new DataObject(['module_name' => 'blog', 'controller_name' => 'search', 'action_name' => 'result', 'params' => []]);
     }
     if ($parts[0] == 'tag' && isset($parts[1])) {
         $tag = $this->tagFactory->create()->getCollection()->addFieldToFilter('url_key', $parts[1])->getFirstItem();
         if ($tag->getId()) {
             return new DataObject(['module_name' => 'blog', 'controller_name' => 'tag', 'action_name' => 'view', 'params' => ['id' => $tag->getId()]]);
         } else {
             return false;
         }
     }
     if ($parts[0] == 'author' && isset($parts[1])) {
         $author = $this->authorFactory->create()->getCollection()->addFieldToFilter('user_id', $parts[1])->getFirstItem();
         if ($author->getId()) {
             return new DataObject(['module_name' => 'blog', 'controller_name' => 'author', 'action_name' => 'view', 'params' => ['id' => $author->getId()]]);
         } else {
             return false;
         }
     }
     if ($parts[0] == 'rss' && isset($parts[1])) {
         $category = $this->categoryFactory->create()->getCollection()->addFieldToFilter('url_key', $parts[1])->getFirstItem();
         if ($category->getId()) {
             return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'rss', 'params' => ['id' => $category->getId()]]);
         } else {
             return false;
         }
     } elseif ($parts[0] == 'rss') {
         return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'rss', 'params' => []]);
     }
     $post = $this->postFactory->create()->getCollection()->addAttributeToFilter('url_key', $urlKey)->getFirstItem();
     if ($post->getId()) {
         return new DataObject(['module_name' => 'blog', 'controller_name' => 'post', 'action_name' => 'view', 'params' => ['id' => $post->getId()]]);
     }
     $category = $this->categoryFactory->create()->getCollection()->addAttributeToFilter('url_key', $urlKey)->getFirstItem();
     if ($category->getId()) {
         return new DataObject(['module_name' => 'blog', 'controller_name' => 'category', 'action_name' => 'view', 'params' => ['id' => $category->getId()]]);
     }
     return false;
 }