Example #1
0
 /**
  * Tries to find a route matching the current request. If found the defined action is called.
  */
 protected function dispatch()
 {
     $httpMethod = $_SERVER['REQUEST_METHOD'];
     $uri = rawurldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
     $routeInfo = $this->dispatcher->dispatch($httpMethod, $uri);
     if (!isset($routeInfo[0])) {
         throw new RuntimeException('Could not dispatch request.');
     }
     switch ($routeInfo[0]) {
         case FastRoute\Dispatcher::NOT_FOUND:
             $responder = new NotFoundResponder($this->config);
             $responder->__invoke();
             break;
         case FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
             $responder = new HttpResponder($this->config);
             $responder->methodNotAllowed();
             break;
         case FastRoute\Dispatcher::FOUND:
             $handler = $routeInfo[1];
             $arguments = $routeInfo[2];
             $this->runAction($handler, $arguments);
             break;
         default:
             throw new RuntimeException('Could not dispatch request.');
     }
 }
Example #2
0
 /**
  * Renders requested article and sends it to client.
  *
  * @param array $arguments
  */
 public function __invoke(array $arguments)
 {
     try {
         $slug = $arguments['slug'];
         $article = $this->domain->getArticleBySlug($slug);
         $this->responder->setTitle($article->getMetaTitle());
         $this->responder->setDescription($article->getDescription());
         $this->responder->setFeedUrl($this->feedDomain->getFeedUrlPath());
         $this->responder->setIndex($this->domain->getIndex());
         $this->responder->assign('article', $article);
         $this->responder->assign('navActive', 'blog');
         $this->responder->__invoke();
     } catch (NotFoundException $e) {
         $responder = new NotFoundResponder($this->config);
         $responder->assign('info', $e->getMessage());
         $responder->__invoke();
     }
 }
Example #3
0
 /**
  * Renders requested article and sends it to client.
  *
  * @param array $arguments
  */
 public function __invoke(array $arguments)
 {
     try {
         $category = $arguments['slug'] ?? '';
         $page = (int) ($arguments['page'] ?? 0);
         $this->responder->setPage($page);
         $this->responder->setTitle($this->domain->getTitle($page, $category));
         $this->responder->setDescription($this->domain->getDescription($page, $category));
         $this->responder->setIndex($this->domain->getIndex($page, $category));
         $this->responder->setFeedUrl($this->feedDomain->getFeedUrlPath($category));
         $this->responder->assign('articles', $this->domain->getArticles($page, $category));
         $this->responder->assign('urlNextPage', $this->domain->getUrlNextPage($page, $category));
         $this->responder->assign('urlPrevPage', $this->domain->getUrlPrevPage($page, $category));
         $this->responder->assign('navActive', 'blog');
         $this->responder->assign('showTitle', $page < 2);
         $this->responder->__invoke();
     } catch (NotFoundException $e) {
         $responder = new NotFoundResponder($this->config);
         $responder->assign('info', $e->getMessage());
         $responder->__invoke();
     }
 }