Example #1
0
 /**
  * Wraps the controller or function into a callable closure
  *
  * @param RouteInterface $route
  * @return \Closure
  * @throws \HttpRuntimeException
  */
 protected function getNextCallable(RouteInterface $route)
 {
     $controller = $route->getController();
     $controllerMethod = $route->getControllerMethod();
     $namespace = $this->getControllerNamespace();
     $payload = $route->getRouteParameters();
     if (is_callable($controller)) {
         $args = $this->getFunctionArgs($controller);
         $next = function () use($controller, $args) {
             return call_user_func_array($controller, $args);
         };
     } else {
         if (strContains('\\', $controller)) {
             $class = $controller;
         } else {
             $class = $namespace . '\\' . $controller;
         }
         if (class_exists($class, true)) {
             $obj = $this->makeController($class);
             $obj->setApplication($this->application);
             $args = $this->getFunctionArgs($controller, $controllerMethod);
             $next = function () use($obj, $args, $controllerMethod, $payload) {
                 return $this->runController($obj, $controllerMethod, $args);
             };
         } else {
             throw new ControllerNotFoundException();
         }
     }
     return $next;
 }