Example #1
0
 /**
  * Get arguments
  *
  * @return array
  */
 public function getArguments()
 {
     if (!$this->request->isParsed()) {
         $this->parseRequest();
     }
     return $this->request->getArguments();
 }
Example #2
0
 private function routeRequest(Request $request, Service $service)
 {
     $desired_method = String::underscoreToCamelCase($request->getMethod());
     $requested_method = $request->getRequestMethod() . $desired_method;
     $method = $requested_method;
     $arguments = $request->getArguments();
     if (!method_exists($service, $method)) {
         $method = $request->getRequestMethod() . 'Router';
         if (!method_exists($service, $method)) {
             throw new MethodNotSupported($request->getService(), $requested_method);
         }
         array_splice($arguments, 0, 0, array($request->getMethod()));
     }
     $output = call_user_func_array(array($service, $method), $arguments);
     $this->response->setResponse($output);
 }
Example #3
0
 public static function route(Request $request)
 {
     $controller = $request->getController() . 'Controller';
     $method = $request->getMethod();
     $args = $request->getArguments();
     $controllerFile = SITE_PATH . 'controllers/' . $controller . '.php';
     /* Given that controllerFile exists and is readable,
        include the file, instantiate controller-class and call method
        (default 'index') */
     if (is_readable($controllerFile)) {
         require_once $controllerFile;
         $controller = new $controller();
         $method = is_callable([$controller, $method]) ? $method : 'index';
         if (!empty($args)) {
             call_user_func_array([$controller, $method], $args);
         } else {
             call_user_func([$controller, $method]);
         }
         return;
     }
     throw new Exception('404 -  ' . $controller . ' not found');
 }
Example #4
0
 public function __construct(Request $r)
 {
     $controller = $r->getController() . 'Controller';
     $controllerPath = ROOT . 'controllers' . DS . $controller . '.php';
     $method = $r->getMethod();
     $arguments = $r->getArguments();
     //			echo "<hr/>$controllerPath<hr/>";
     if (is_readable($controllerPath)) {
         require_once $controllerPath;
         $controller = new $controller();
         if (!is_callable(array($controller, $method))) {
             $method = 'index';
         }
         if (isset($arguments)) {
             call_user_func_array(array($controller, $method), $arguments);
         } else {
             call_user_func(array($controller, $method));
         }
     } else {
         throw new Exception("<b>El controlador no se encuentra: " . $controllerPath . "</b>");
     }
 }
Example #5
0
 public static function run(Request $request)
 {
     $controller = $request->getController() . "Controller";
     $rout_controller = ROOT . 'protected' . DS . 'controllers' . DS . $controller . '.php';
     $method = $request->getMethod();
     $arguments = $request->getArguments();
     if (is_readable($rout_controller)) {
         require_once $rout_controller;
         $controller = new $controller();
         if (is_callable(array($controller, $method))) {
             $metodo = $request->getMethod();
         } else {
             $metodo = 'index';
         }
         if (isset($arguments)) {
             call_user_func_array(array($controller, $method), $arguments);
         } else {
             call_user_func($controller, $method);
         }
     } else {
         throw new Exception('EL ARCHIVO: "' . $rout_controller . '" NO FUE ENCONTRADO');
     }
 }