KumbiaPHP beta2-dev
Framework PHP en español
dispatcher.php
Ir a la documentación de este archivo.
00001 <?php
00022 final class Dispatcher
00023 {
00029     private static $_controller;
00030 
00036     public static function execute ($route)
00037     {
00038         extract($route, EXTR_OVERWRITE);
00039 
00040                 if (!include_once APP_PATH . "controllers/$controller_path".'_controller.php') throw new KumbiaException(NULL,'no_controller');
00041 
00042                 //Asigna el controlador activo
00043                 $app_controller = Util::camelcase($controller) . 'Controller';
00044                 $cont = self::$_controller = new $app_controller($module, $controller, $action, $parameters);
00045                 View::select($action);
00046                 View::setPath($controller_path);
00047                                 
00048                 // Se ejecutan los filtros initialize y before
00049                 if($cont->k_callback(TRUE) === FALSE) {
00050                         return $cont;
00051                 }
00052 
00053                 //Se ejecuta el metodo con el nombre de la accion
00054                 //en la clase de acuerdo al convenio
00055                 if(!method_exists($cont, $cont->action_name)){                  
00056                         throw new KumbiaException(NULL,'no_action');    
00057                 }
00058                 
00059                 //Obteniendo el metodo
00060                 $reflectionMethod = new ReflectionMethod($cont, $cont->action_name);
00061         
00062                 //k_callback y __constructor metodo reservado
00063                 if($reflectionMethod->name == 'k_callback' || $reflectionMethod->isConstructor()){
00064                     throw new KumbiaException('Esta intentando ejecutar un método reservado de KumbiaPHP');
00065                 }
00066         
00067                 //se verifica que el metodo sea public
00068                 if(!$reflectionMethod->isPublic()){
00069                     throw new KumbiaException(NULL,'no_action');
00070                 }
00071                 
00072                 //se verifica que los parametros que recibe 
00073                 //la action sea la cantidad correcta
00074                 $num_params = count($cont->parameters);
00075                 if($cont->limit_params && ($num_params < $reflectionMethod->getNumberOfRequiredParameters() ||
00076                                            $num_params > $reflectionMethod->getNumberOfParameters())){
00077                         throw new KumbiaException("Número de parámetros erróneo para ejecutar la acción \"{$cont->action_name}\" en el controlador \"$controller\"");
00078                 }
00079                 $reflectionMethod->invokeArgs($cont, $cont->parameters);
00080 
00081                 //Corre los filtros after y finalize
00082                 $cont->k_callback();
00083                 
00084                 //Si esta routed volver a ejecutar
00085                 if (Router::getRouted()){
00086                         Router::setRouted(FALSE);
00087                         return Dispatcher::execute(Router::get());// Vuelve a ejecutar el dispatcher
00088                 }
00089 
00090                 return $cont;
00091     }
00097     public static function get_controller()
00098     {
00099         return self::$_controller;
00100     }
00101 }
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Enumeraciones