Example #1
0
 public function getController()
 {
     $router = new Router();
     $router->buildRoutesForApplication($this->name());
     try {
         // On récupère la route correspondante à l'URL.
         $matchedRoute = $router->getRoute($this->httpRequest->requestURI(), $this->name());
     } catch (\RuntimeException $e) {
         if ($e->getCode() == Router::NO_ROUTE) {
             // Si aucune route ne correspond, c'est que la page demandée n'existe pas.
             $this->httpResponse->redirect404();
         }
     }
     // On ajoute les variables de l'URL au tableau $_GET.
     $_GET = array_merge($_GET, $matchedRoute->vars());
     // On instancie le contrôleur.
     $controllerClass = 'App\\' . $this->name . '\\Modules\\' . $matchedRoute->module() . '\\' . $matchedRoute->module() . 'Controller';
     return new $controllerClass($this, $matchedRoute->module(), $matchedRoute->action());
 }