You are here

public function Response::setStatusCode in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Response.php \Symfony\Component\HttpFoundation\Response::setStatusCode()

Sets the response status code.

Parameters

int $code HTTP status code:

mixed $text HTTP status text:

If the status text is null it will be automatically populated for the known status codes and left empty otherwise.

Return value

Response

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
Constructor.

File

vendor/symfony/http-foundation/Response.php, line 450

Class

Response
Response represents an HTTP response.

Namespace

Symfony\Component\HttpFoundation

Code

public function setStatusCode($code, $text = null) {
  $this->statusCode = $code = (int) $code;
  if ($this
    ->isInvalid()) {
    throw new \InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code));
  }
  if (null === $text) {
    $this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] : '';
    return $this;
  }
  if (false === $text) {
    $this->statusText = '';
    return $this;
  }
  $this->statusText = $text;
  return $this;
}