diff --git a/src/Router/Controller.php b/src/Router/Controller.php index a99c4b6..6062d85 100644 --- a/src/Router/Controller.php +++ b/src/Router/Controller.php @@ -57,6 +57,22 @@ abstract class Controller ); } + /** + * Build a redirect response. + * @param string $to Location to redirect to. + * @param StatusCode $statusCode The status code to send back. 301 Moved Permanently by default. + * @return ResponseInterface Built response. + */ + public function redirect(string $to, StatusCode $statusCode = StatusCode::MovedPermanently): ResponseInterface + { + return new Response( + // Pass the status code. + status: $statusCode->value, + // Pass redirect location. + headers: ["Location" => $to], + ); + } + /** * Build a text response. * @param string $value The text value to pass.