/** * Realiza el dispatch de una ruta * * @return Object */ public static function execute($route) { extract($route, EXTR_OVERWRITE); if (!(include_once APP_PATH . "controllers/{$controller_path}" . '_controller.php')) { throw new KumbiaException(NULL, 'no_controller'); } //Asigna el controlador activo $app_controller = Util::camelcase($controller) . 'Controller'; $cont = self::$_controller = new $app_controller($module, $controller, $action, $parameters); View::select($action); View::setPath($controller_path); // Se ejecutan los filtros before if ($cont->k_callback('initialize') === FALSE) { return $cont; } if ($cont->k_callback('before_filter') === FALSE) { return $cont; } //Se ejecuta el metodo con el nombre de la accion //en la clase de acuerdo al convenio if (!method_exists($cont, $action)) { throw new KumbiaException(NULL, 'no_action'); } //Obteniendo el metodo $reflectionMethod = new ReflectionMethod($cont, $action); //k_callback y __constructor metodo reservado if ($reflectionMethod->name == 'k_callback' || $reflectionMethod->isConstructor()) { throw new KumbiaException('Esta intentando ejecutar un método reservado de KumbiaPHP'); } //se verifica que el metodo sea public if (!$reflectionMethod->isPublic()) { throw new KumbiaException(NULL, 'no_action'); } //se verifica que los parametros que recibe //la action sea la cantidad correcta $num_params = count($parameters); if ($cont->limit_params && ($num_params < $reflectionMethod->getNumberOfRequiredParameters() || $num_params > $reflectionMethod->getNumberOfParameters())) { throw new KumbiaException("Número de parámetros erroneo para ejecutar la acción \"{$action}\" en el controlador \"{$controller}\""); } $reflectionMethod->invokeArgs($cont, $parameters); //Corre los filtros after $cont->k_callback('after_filter'); $cont->k_callback('finalize'); //Si esta routed volver a ejecutar if (Router::getRouted()) { Router::setRouted(FALSE); return Dispatcher::execute(Router::get()); // Vuelve a ejecutar el dispatcher } return $cont; }
/** * Función Principal donde se ejecutan los controladores * * @params string $url url * @return boolean */ public static function main($url) { /** * El Router analiza la url **/ Router::rewrite($url); /** * Ciclo del enrutador */ $controller = Dispatcher::execute(); while (Router::getRouted()) { Router::setRouted(false); $controller = Dispatcher::execute(); } /** * Renderiza la vista **/ if ($controller->view || $controller->template) { require CORE_PATH . 'kumbia/view.php'; View::render($controller, $url); } else { ob_end_flush(); } // Fin del request exit; }