38 private static $_vars = array(
42 'controller' =>
'index',
44 'parameters' => array(),
45 'controller_path' =>
'index'
53 private static $_routed = FALSE;
65 if (stripos(
$url,
'/../') !==
false)
69 self::$_vars[
'route'] =
$url;
71 self::$_vars[
'method'] = $_SERVER[
'REQUEST_METHOD'];
79 return self::_dispatch();
89 private static function _ifRouted(
$url)
92 $routes = $routes[
'routes'];
95 if (isset($routes[
$url])) {
100 foreach ($routes as $key => $val) {
102 return rtrim($val,
'*') .
$url;
105 if (strripos($key,
'*', -1)) {
106 $key = rtrim($key,
'*');
107 if (strncmp($url, $key, strlen($key)) == 0)
108 return str_replace($key, rtrim($val,
'*'), $url);
120 private static function _rewrite($url)
123 if ($url ==
'/')
return;
127 $url_items = explode(
'/', trim($url,
'/'));
130 if (is_dir(
APP_PATH .
"controllers/$url_items[0]")) {
131 self::$_vars[
'module'] = $url_items[0];
134 if (next($url_items) ===
false) {
135 self::$_vars[
'controller_path'] =
"$url_items[0]/index";
141 self::$_vars[
'controller'] = current($url_items);
142 self::$_vars[
'controller_path'] = (self::$_vars[
'module']) ?
"$url_items[0]/$url_items[1]" : current($url_items);
145 if (next($url_items) ===
false)
return;
148 self::$_vars[
'action'] = current($url_items);
151 if (next($url_items) ===
false)
return;
154 self::$_vars[
'parameters'] = array_slice($url_items, key($url_items));
162 private static function _dispatch()
165 extract(self::$_vars, EXTR_OVERWRITE);
167 if (!include_once
APP_PATH .
"controllers/$controller_path" .
'_controller.php')
174 $cont =
new $app_controller($module, $controller, $action, $parameters);
177 if ($cont->k_callback(
true) ===
false) {
183 $reflectionMethod =
new ReflectionMethod($cont, $cont->action_name);
184 }
catch (ReflectionException $e) {
189 if ($cont->action_name ==
'k_callback' || $reflectionMethod->isConstructor()) {
190 throw new KumbiaException(
'Esta intentando ejecutar un método reservado de KumbiaPHP');
195 $num_params = count($cont->parameters);
196 if ($cont->limit_params && ($num_params < $reflectionMethod->getNumberOfRequiredParameters() ||
197 $num_params > $reflectionMethod->getNumberOfParameters())) {
202 $reflectionMethod->invokeArgs($cont, $cont->parameters);
203 }
catch (ReflectionException $e) {
211 if (self::$_routed) {
212 self::$_routed = FALSE;
213 return self::_dispatch();
227 call_user_func_array(array(
'Redirect',
'route_to'), func_get_args());
242 public static function get($var = null)
245 return self::$_vars[$var];
259 public static function redirect($route = null, $seconds = null)
272 public static function toAction($action, $seconds = null)
283 public static function to($params, $intern = FALSE)
285 if($intern) self::$_routed = TRUE;
286 self::$_vars = $params + self::$_vars;