/** * Sends a redirection message to the client * * @param string $path Path of the redirect. The path is an internal routing path. * @param array $params Parameters of the path * @return bool Returns true */ public static function redirect(string $path, array $params = null) : bool { $host = $_SERVER['HTTP_HOST']; $routing = new Routing(); $route = $routing->reverse($path); if (isset($params)) { foreach ($params as $key => $value) { $pattern = sprintf('#\\(\\?P<%s>.*?\\)#', $key); $route = preg_replace($pattern, $value, $route, 1); } } header(sprintf('Location: http://%s/?route=%s', $host, $route)); return true; }