/**
  * 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;
 }
Beispiel #2
0
 /**
  * Realiza el dispatch de una ruta
  *
  * @return Object
  */
 public static function execute()
 {
     extract(Router::get(), EXTR_OVERWRITE);
     $controllers_dir = APP_PATH . 'controllers';
     if ($module) {
         $controllers_dir = $controllers_dir . '/' . $module;
     }
     $app_controller = Util::camelcase($controller) . 'Controller';
     $file = "{$controllers_dir}/{$controller}" . '_controller.php';
     if (!is_file($file)) {
         throw new KumbiaException(null, 'no_controller');
     }
     include_once $file;
     /**
      * Asigna el controlador activo
      **/
     self::$_controller = $activeController = new $app_controller($module, $controller, $action, $id, $all_parameters, $parameters);
     /**
      * Carga de modelos
      **/
     if (Config::get('config.application.database')) {
         if (Config::get('config.application.models_autoload')) {
             Load::models();
         } elseif ($activeController->models !== null) {
             Load::models($activeController->models);
         }
     }
     /**
      * Se ejecutan los filtros before
      */
     if ($activeController->initialize() === false) {
         return $activeController;
     }
     if ($activeController->before_filter() === false) {
         return $activeController;
     }
     /**
      * Se ejecuta el metodo con el nombre de la accion
      * en la clase
      */
     if (!method_exists($activeController, $action)) {
         throw new KumbiaException(null, 'no_action');
     }
     call_user_func_array(array($activeController, $action), $parameters);
     /**
      * Corre los filtros after
      */
     $activeController->after_filter();
     $activeController->finalize();
     /**
      * Elimino del controlador los modelos inyectados
      **/
     foreach (Load::get_injected_models() as $model) {
         unset($activeController->{$model});
     }
     /**
      * Limpia el buffer de modelos inyectados
      **/
     Load::reset_injected_models();
     return $activeController;
 }