public function Response::setStatusCode

Sets the response status code.

@api

Parameters

integer $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

2 calls to Response::setStatusCode()
Response::setNotModified in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php
Modifies the response so that it conforms to the rules defined for a 304 status code.
Response::__construct in drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php
Constructor.

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php, line 396

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;
}