Example #1
0
 /**
  * Start the routing procedure and find a valid route, if any.
  *
  * @access public
  */
 public function route()
 {
     // Start the profiler
     Profiler::register('Core', 'Router');
     // First, let's look at the URL the user supplied
     $requestUrl = array_values(array_filter(explode('/', Request::getUrl())));
     $requestRoute = null;
     // Loop over each route and test to see if they are valid
     foreach (self::$_routes as $route) {
         if ($this->routeTest($requestUrl, $route)) {
             $requestRoute = $route;
             break;
         }
     }
     // We have completed the route matching
     // Finish the setup of the request object
     Profiler::register('Core', 'Request');
     if ($requestRoute) {
         $_GET['controller'] = $route->endpoint['controller'];
         $_GET['action'] = $route->endpoint['action'];
         Request::setUrlFragments(str_replace($this->_routePath, '', Request::getUrl()));
     } else {
         Request::setUrlFragments(Request::getUrl(), true);
     }
     Profiler::deregister('Core', 'Request');
     // Inform the event listener a request has been initialised
     Event::trigger('initRequest', array('controller' => Request::get('controller'), 'action' => Request::get('action')));
     // And stop the profiler
     Profiler::deregister('Core', 'Router');
     Profiler::deregister('Core', 'Front');
     // And dispatch
     Dispatcher::loadController(Request::get('controller'), Request::get('action'));
 }