/** * 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; }
/** * Redirect request with query. * * @param string|array $query */ protected function redirect($query = array()) { if (defined('NO_REDIRECT') && NO_REDIRECT) { return; } $redirect = Communication::useRedirect(); if ($redirect) { /** * @var string $redirectTo */ if (strtolower($redirect) == 'referer') { $redirectTo = preg_replace('/[\\&|\\?]result\\=\\d+/', '', Communication::getReferer()); } else { $redirectTo = preg_replace('/[\\&|\\?]result\\=\\d+/', '', $redirect); } Communication::redirectTo($redirectTo, $query); } }