Ejemplo n.º 1
0
 /**
  * Get the back controller matching with the HTTP request.
  * @return BackController The controller.
  */
 public function getController()
 {
     $router = $this->router();
     $requestURI = $this->httpRequest->requestURI();
     $websiteConfigFile = new Config(__DIR__ . '/../etc/core/website.json');
     $websiteConfig = $websiteConfigFile->read();
     $requestURI = preg_replace('#^' . preg_quote($websiteConfig['root']) . '#', '$1', $requestURI);
     try {
         //Let's get the route matching with the URL
         $matchedRoute = $router->getRouteFromUrl($requestURI);
     } catch (\RuntimeException $e) {
         if ($e->getCode() == Router::NO_ROUTE) {
             //No route matching, the page doesn't exist
             $this->httpResponse->redirect404($this);
             return;
         }
     }
     //Add variables to the $_GET array
     $_GET = array_merge($_GET, $matchedRoute->vars());
     //And then create the controller
     return $this->buildController($matchedRoute->module(), $matchedRoute->action());
 }