Add redirect response builder to controller.
This commit is contained in:
parent
9964d87e1e
commit
46f0ad4ed5
1 changed files with 16 additions and 0 deletions
|
@ -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.
|
* Build a text response.
|
||||||
* @param string $value The text value to pass.
|
* @param string $value The text value to pass.
|
||||||
|
|
Loading…
Reference in a new issue