You are here

public function Response::setStatusCode in RESTful 7.2

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.

Throws

UnprocessableEntityException When the HTTP status code is not valid

Overrides ResponseInterface::setStatusCode

1 call to Response::setStatusCode()
Response::__construct in src/Http/Response.php
Constructor.

File

src/Http/Response.php, line 316
Contains \Drupal\restful\Http\Response.

Class

Response

Namespace

Drupal\restful\Http

Code

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