function Response::setStatusCode
Sets the response status code.
If the status text is null it will be automatically populated for the known status codes and left empty otherwise.
@final
Return value
$this
Throws
\InvalidArgumentException When the HTTP status code is not valid
3 calls to Response::setStatusCode()
- BinaryFileResponse::prepare in vendor/
symfony/ http-foundation/ BinaryFileResponse.php - Prepares the Response before it is sent to the client.
- Response::setNotModified in vendor/
symfony/ http-foundation/ Response.php - Modifies the response so that it conforms to the rules defined for a 304 status code.
- Response::__construct in vendor/
symfony/ http-foundation/ Response.php
File
-
vendor/
symfony/ http-foundation/ Response.php, line 469
Class
- Response
- Response represents an HTTP response.
Namespace
Symfony\Component\HttpFoundationCode
public function setStatusCode(int $code, ?string $text = null) : static {
$this->statusCode = $code;
if ($this->isInvalid()) {
throw new \InvalidArgumentException(\sprintf('The HTTP status code "%s" is not valid.', $code));
}
if (null === $text) {
$this->statusText = self::$statusTexts[$code] ?? 'unknown status';
return $this;
}
$this->statusText = $text;
return $this;
}