Exemplo n.º 1
0
 /**
  * Route to the correct controller
  *
  * @return void
  */
 public function route()
 {
     $this->routeMatch->match($this->routes);
     $controller = $this->routeMatch->getController();
     if (null === $controller) {
         $controller = $this->routeMatch->getDefaultController();
     }
     if (null !== $controller) {
         // If controller is a closure
         if ($controller instanceof \Closure) {
             $this->controller = $controller;
             $this->controllerClass = $controller;
             if ($this->routeMatch->hasDispatchParams()) {
                 $this->addDispatchParams($this->routeMatch->getRoute(), $this->routeMatch->getDispatchParams());
             }
             // Else if controller is a class
         } else {
             if (class_exists($controller)) {
                 $this->controllerClass = $controller;
                 // If parameters are found, add them for dispatch
                 if ($this->routeMatch->hasRouteParams()) {
                     $this->addRouteParams($controller, $this->routeMatch->getRouteParams());
                 }
                 // If the controller has route parameters
                 if (isset($this->routeParams['*']) || isset($this->routeParams[$controller])) {
                     if (isset($this->routeParams['*']) && isset($this->routeParams[$controller])) {
                         $routeParams = array_merge($this->routeParams['*'], $this->routeParams[$controller]);
                     } else {
                         if (isset($this->routeParams['*'])) {
                             $routeParams = $this->routeParams['*'];
                         } else {
                             $routeParams = $this->routeParams[$controller];
                         }
                     }
                     $reflect = new \ReflectionClass($controller);
                     $this->controller = $reflect->newInstanceArgs($routeParams);
                     // Else, just instantiate the controller
                 } else {
                     $this->controller = new $controller();
                 }
                 if ($this->routeMatch->hasDispatchParams() && null !== $this->routeMatch->getAction()) {
                     $this->addDispatchParams($this->routeMatch->getRoute(), $this->routeMatch->getDispatchParams());
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Method to process if a route was not found
  *
  * @param  boolean $exit
  * @return void
  */
 public function noRouteFound($exit = true)
 {
     $this->routeMatch->noRouteFound($exit);
 }