classes/Route.php
public static function dispatch($URL=null, $method=null, $return_route=false){
        if (!$URL)     $URL     = Request::URI();
        if (!$method)  $method  = Request::method();

        $__deferred_send = new Deferred(function(){
          if (Options::get('core.response.autosend',true)){
            Response::send();
          }
        });

        if (empty(static::$optimized_tree)) {
          foreach ((array)static::$routes as $group => $routes){
              foreach ($routes as $route) {
                  if (is_a($route, 'Route') && $route->match($URL,$method)){
                    if ($return_route){
                      return $route;
                    } else {
                      $route->run($route->extractArgs($URL),$method);
                      return true;
                    }
                  }
              }
          }
        } else {
          $routes =& static::$optimized_tree;
          foreach (explode('/',trim($URL,'/')) as $segment) {
            if (is_array($routes) && isset($routes[$segment])) $routes =& $routes[$segment];
              // Root-level dynamic routes Ex: "/:param"
              else if (is_array($routes) && isset($routes[''])) $routes =& $routes[''];
            else break;
          }
          if (is_array($routes) && isset($routes[0]) && !is_array($routes[0])) foreach ((array)$routes as $route) {
              if (is_a($route, __CLASS__) && $route->match($URL, $method)){
                    if ($return_route){
                      return $route;
                    } else {
                      $route->run($route->extractArgs($URL),$method);
                      return true;
                    }
              }
          }
        }

        Response::status(404, '404 Resource not found.');
        foreach (array_filter(array_merge(
          (static::trigger(404)?:[]),
          (Event::trigger(404)?:[])
        )) as $res){
           Response::add($res);
        }
        return false;
    }
public static function dispatch($URL=null, $method=null, $return_route=false){
        if (!$URL)     $URL     = Request::URI();
        if (!$method)  $method  = Request::method();

        $__deferred_send = new Deferred(function(){
          if (Options::get('core.response.autosend',true)){
            Response::send();
          }
        });

        if (empty(static::$optimized_tree)) {
          foreach ((array)static::$routes as $group => $routes){
              foreach ($routes as $route) {
                  if (is_a($route, 'Route') && $route->match($URL,$method)){
                    if ($return_route){
                      return $route;
                    } else {
                      $route->run($route->extractArgs($URL),$method);
                      return true;
                    }
                  }
              }
          }
        } else {
          $routes =& static::$optimized_tree;
          foreach (explode('/',trim($URL,'/')) as $segment) {
            if (is_array($routes) && isset($routes[$segment])) $routes =& $routes[$segment];
              // Root-level dynamic routes Ex: "/:param"
              else if (is_array($routes) && isset($routes[''])) $routes =& $routes[''];
            else break;
          }
          if (is_array($routes) && isset($routes[0]) && !is_array($routes[0])) foreach ((array)$routes as $route) {
              if (is_a($route, __CLASS__) && $route->match($URL, $method)){
                    if ($return_route){
                      return $route;
                    } else {
                      $route->run($route->extractArgs($URL),$method);
                      return true;
                    }
              }
          }
        }

        Response::status(404, '404 Resource not found.');
        foreach (array_filter(array_merge(
          (static::trigger(404)?:[]),
          (Event::trigger(404)?:[])
        )) as $res){
           Response::add($res);
        }
        return false;
    }
public static function dispatch ( $ URL = null , $ method = null , $ return_route = false ) { if ( ! $ URL ) $ URL = Request :: URI ( ) ; if ( ! $ method ) $ method = Request :: method ( ) ; $ __deferred_send = new Deferred ( function ( ) { if ( Options :: get ( 'core.response.autosend' , true ) ) { Response :: send ( ) ; } } ) ; if ( empty ( static :: $ optimized_tree ) ) { foreach ( ( array ) static :: $ routes as $ group => $ routes ) { foreach ( $ routes as $ route ) { if ( is_a ( $ route , 'Route' ) && $ route -> match ( $ URL , $ method ) ) { if ( $ return_route ) { return $ route ; } else { $ route -> run ( $ route -> extractArgs ( $ URL ) , $ method ) ; return true ; } } } } } else { $ routes = & static :: $ optimized_tree ; foreach ( explode ( '/' , trim ( $ URL , '/' ) ) as $ segment ) { if ( is_array ( $ routes ) && isset ( $ routes [ $ segment ] ) ) $ routes = & $ routes [ $ segment ] ; // Root-level dynamic routes Ex: "/:param" else if ( is_array ( $ routes ) && isset ( $ routes [ '' ] ) ) $ routes = & $ routes [ '' ] ; else break ; } if ( is_array ( $ routes ) && isset ( $ routes [ 0 ] ) && ! is_array ( $ routes [ 0 ] ) ) foreach ( ( array ) $ routes as $ route ) { if ( is_a ( $ route , __CLASS__ ) && $ route -> match ( $ URL , $ method ) ) { if ( $ return_route ) { return $ route ; } else { $ route -> run ( $ route -> extractArgs ( $ URL ) , $ method ) ; return true ; } } } } Response :: status ( 404 , '404 Resource not found.' ) ; foreach ( array_filter ( array_merge ( ( static :: trigger ( 404 ) ? : [ ] ) , ( Event :: trigger ( 404 ) ? : [ ] ) ) ) as $ res ) { Response :: add ( $ res ) ; } return false ; }
Start the route dispatcher and resolve the URL request.
@param  string $URL The URL to match onto.
@param  string $method The HTTP method.
@param  bool $return_route If setted to true it will *NOT* execute the route but it will return her.
@return boolean true if a route callback was executed.
Start the route dispatcher and resolve the URL request .