/** * Get arguments * * @return array */ public function getArguments() { if (!$this->request->isParsed()) { $this->parseRequest(); } return $this->request->getArguments(); }
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); }
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'); }
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>"); } }
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'); } }