/** * Takes request uri and routes to controller. * @return bool * @throws \Exception */ public function routing() { $routes = array_merge($this->priorityRoutes, $this->routes); $uri = $_SERVER['REQUEST_URI']; $method = Communication::getMethod(); /** * @var Route $route */ foreach ($routes as $route) { $matches = $route->match($uri, $method); if ($matches) { $params = $route->params($uri, $method); $array = $route->getCallback(); $controller = str_replace('/', '\\', $array[0]); /** * @var BaseController */ $ctrl = Container::instance()->make($controller); $ctrl->init(); $action = $array[1]; if ($action == ':action') { $action = str_replace(':action', $matches['action'], $action); } try { $ctrl->executeAction($action, $params); $this->routed = true; $this->current_route = $route; } catch (\Exception $ex) { if (defined('WP_DEBUG') && WP_DEBUG) { throw $ex; } $this->routed = false; } return $this->routed; } } $this->routed = false; return $this->routed; }