public function route($uri = false) { if (!$uri) { if (empty($_SERVER['REDIRECT_URL'])) { if (stristr($_SERVER['REQUEST_URI'], '?') !== false) { $uri = stristr($_SERVER['REQUEST_URI'], '?', true); } else { $uri = $_SERVER['REQUEST_URI']; } } else { $uri = $_SERVER['REDIRECT_URL']; } } $context = new RequestContext($uri); $locator = new FileLocator(array(dirname(__FILE__) . '/../conf')); $router = new Router(new PhpFileLoader($locator), 'routes.php', array('cache_dir' => null), $context); if (!$uri) { $uri = $this->httpRequest->getPathInfo(); } $this->route = $router->match($uri); $this->controller = new $this->route['class']($this); if (DEBUG_BAR) { $this->debugbar->addCollector(new ConfigCollector($this->config)); $debugbarRenderer = $this->debugbar->getJavascriptRenderer(); $this->debugbar["messages"]->addMessage("Debug Bar enabled"); $this->controller->setData('debugbarRenderer', $debugbarRenderer); } //set action to index is its not set if (empty($this->route['action'])) { $this->route['action'] = $this->route['_route'] == '/' ? "index" : $this->route['_route']; } $action = $this->route['action']; if (!method_exists($this->controller, $action)) { throw new Exception('Method Not found'); } $this->controller->{$action}(); }