KumbiaPHP  beta2
Framework PHP
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Páginas
dispatcher.php
Ir a la documentación de este archivo.
1 <?php
22 final class Dispatcher
23 {
29  private static $_controller;
30 
36  public static function execute ($route)
37  {
38  extract($route, EXTR_OVERWRITE);
39 
40  if (!include_once APP_PATH . "controllers/$controller_path".'_controller.php') throw new KumbiaException(NULL,'no_controller');
41 
42  //Asigna el controlador activo
43  $app_controller = Util::camelcase($controller) . 'Controller';
44  $cont = self::$_controller = new $app_controller($module, $controller, $action, $parameters);
45  View::select($action);
46  View::setPath($controller_path);
47 
48  // Se ejecutan los filtros initialize y before
49  if($cont->k_callback(TRUE) === FALSE) {
50  return $cont;
51  }
52 
53  //Se ejecuta el metodo con el nombre de la accion
54  //en la clase de acuerdo al convenio
55  if(!method_exists($cont, $cont->action_name)){
56  throw new KumbiaException(NULL,'no_action');
57  }
58 
59  //Obteniendo el metodo
60  $reflectionMethod = new ReflectionMethod($cont, $cont->action_name);
61 
62  //k_callback y __constructor metodo reservado
63  if($reflectionMethod->name == 'k_callback' || $reflectionMethod->isConstructor()){
64  throw new KumbiaException('Esta intentando ejecutar un método reservado de KumbiaPHP');
65  }
66 
67  //se verifica que el metodo sea public
68  if(!$reflectionMethod->isPublic()){
69  throw new KumbiaException(NULL,'no_action');
70  }
71 
72  //se verifica que los parametros que recibe
73  //la action sea la cantidad correcta
74  $num_params = count($cont->parameters);
75  if($cont->limit_params && ($num_params < $reflectionMethod->getNumberOfRequiredParameters() ||
76  $num_params > $reflectionMethod->getNumberOfParameters())){
77  throw new KumbiaException("Número de parámetros erróneo para ejecutar la acción \"{$cont->action_name}\" en el controlador \"$controller\"");
78  }
79  $reflectionMethod->invokeArgs($cont, $cont->parameters);
80 
81  //Corre los filtros after y finalize
82  $cont->k_callback();
83 
84  //Si esta routed volver a ejecutar
85  if (Router::getRouted()){
86  Router::setRouted(FALSE);
87  return Dispatcher::execute(Router::get());// Vuelve a ejecutar el dispatcher
88  }
89 
90  return $cont;
91  }
97  public static function get_controller()
98  {
99  return self::$_controller;
100  }
101 }