ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\HTTP\Response Class Reference

This class represents a single HTTP response. More...

+ Inheritance diagram for Sabre\HTTP\Response:
+ Collaboration diagram for Sabre\HTTP\Response:

Public Member Functions

 __construct ($status=null, array $headers=null, $body=null)
 Creates the response object. More...
 
 getStatus ()
 Returns the current HTTP status code. More...
 
 getStatusText ()
 Returns the human-readable status string. More...
 
 setStatus ($status)
 Sets the HTTP status code. More...
 
 __toString ()
 Serializes the response object as a string. More...
 
- Public Member Functions inherited from Sabre\HTTP\Message
 getBodyAsStream ()
 Returns the body as a readable stream resource. More...
 
 getBodyAsString ()
 Returns the body as a string. More...
 
 getBody ()
 Returns the message body, as it's internal representation. More...
 
 setBody ($body)
 Replaces the body resource with a new stream or string. More...
 
 getHeaders ()
 Returns all the HTTP headers as an array. More...
 
 hasHeader ($name)
 Will return true or false, depending on if a HTTP header exists. More...
 
 getHeader ($name)
 Returns a specific HTTP header, based on it's name. More...
 
 getHeaderAsArray ($name)
 Returns a HTTP header as an array. More...
 
 setHeader ($name, $value)
 Updates a HTTP header. More...
 
 setHeaders (array $headers)
 Sets a new set of HTTP headers. More...
 
 addHeader ($name, $value)
 Adds a HTTP header. More...
 
 addHeaders (array $headers)
 Adds a new set of HTTP headers. More...
 
 removeHeader ($name)
 Removes a HTTP header. More...
 
 setHttpVersion ($version)
 Sets the HTTP version. More...
 
 getHttpVersion ()
 Returns the HTTP version. More...
 

Static Public Attributes

static $statusCodes
 

Protected Attributes

 $status
 
 $statusText
 
- Protected Attributes inherited from Sabre\HTTP\Message
 $body
 
 $headers = []
 
 $httpVersion = '1.1'
 

Detailed Description

This class represents a single HTTP response.

Author
Evert Pot (http://evertpot.com/) http://sabre.io/license/ Modified BSD License

Definition at line 12 of file Response.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\HTTP\Response::__construct (   $status = null,
array  $headers = null,
  $body = null 
)

Creates the response object.

Parameters
string | int$status
array$headers
resource$body

Definition at line 104 of file Response.php.

References Sabre\HTTP\Message\$body, Sabre\HTTP\Message\$headers, Sabre\HTTP\Response\$status, Sabre\HTTP\Message\setBody(), Sabre\HTTP\Message\setHeaders(), and Sabre\HTTP\Response\setStatus().

104  {
105 
106  if (!is_null($status)) $this->setStatus($status);
107  if (!is_null($headers)) $this->setHeaders($headers);
108  if (!is_null($body)) $this->setBody($body);
109 
110  }
setStatus($status)
Sets the HTTP status code.
Definition: Response.php:150
setBody($body)
Replaces the body resource with a new stream or string.
Definition: Message.php:103
setHeaders(array $headers)
Sets a new set of HTTP headers.
Definition: Message.php:216
+ Here is the call graph for this function:

Member Function Documentation

◆ __toString()

Sabre\HTTP\Response::__toString ( )

Serializes the response object as a string.

This is useful for debugging purposes.

Returns
string

Definition at line 179 of file Response.php.

References $key, Sabre\HTTP\Message\getBodyAsString(), Sabre\HTTP\Message\getHeaders(), Sabre\HTTP\Response\getStatus(), and Sabre\HTTP\Response\getStatusText().

179  {
180 
181  $str = 'HTTP/' . $this->httpVersion . ' ' . $this->getStatus() . ' ' . $this->getStatusText() . "\r\n";
182  foreach ($this->getHeaders() as $key => $value) {
183  foreach ($value as $v) {
184  $str .= $key . ": " . $v . "\r\n";
185  }
186  }
187  $str .= "\r\n";
188  $str .= $this->getBodyAsString();
189  return $str;
190 
191  }
getStatus()
Returns the current HTTP status code.
Definition: Response.php:118
getHeaders()
Returns all the HTTP headers as an array.
Definition: Message.php:116
getBodyAsString()
Returns the body as a string.
Definition: Message.php:68
getStatusText()
Returns the human-readable status string.
Definition: Response.php:131
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getStatus()

Sabre\HTTP\Response::getStatus ( )

Returns the current HTTP status code.

Returns
int

Implements Sabre\HTTP\ResponseInterface.

Definition at line 118 of file Response.php.

References Sabre\HTTP\Response\$status.

Referenced by Sabre\HTTP\Response\__toString().

118  {
119 
120  return $this->status;
121 
122  }
+ Here is the caller graph for this function:

◆ getStatusText()

Sabre\HTTP\Response::getStatusText ( )

Returns the human-readable status string.

In the case of a 200, this may for example be 'OK'.

Returns
string

Implements Sabre\HTTP\ResponseInterface.

Definition at line 131 of file Response.php.

References Sabre\HTTP\Response\$statusText.

Referenced by Sabre\HTTP\Response\__toString().

131  {
132 
133  return $this->statusText;
134 
135  }
+ Here is the caller graph for this function:

◆ setStatus()

Sabre\HTTP\Response::setStatus (   $status)

Sets the HTTP status code.

This can be either the full HTTP status code with human readable string, for example: "403 I can't let you do that, Dave".

Or just the code, in which case the appropriate default message will be added.

Parameters
string | int$status
Exceptions

Implements Sabre\HTTP\ResponseInterface.

Definition at line 150 of file Response.php.

References Sabre\HTTP\Response\$status, and Sabre\HTTP\Response\$statusText.

Referenced by Sabre\HTTP\Response\__construct().

150  {
151 
152  if (ctype_digit($status) || is_int($status)) {
153 
154  $statusCode = $status;
155  $statusText = isset(self::$statusCodes[$status]) ? self::$statusCodes[$status] : 'Unknown';
156 
157  } else {
158  list(
159  $statusCode,
161  ) = explode(' ', $status, 2);
162  }
163  if ($statusCode < 100 || $statusCode > 999) {
164  throw new \InvalidArgumentException('The HTTP status code must be exactly 3 digits');
165  }
166 
167  $this->status = $statusCode;
168  $this->statusText = $statusText;
169 
170  }
+ Here is the caller graph for this function:

Field Documentation

◆ $status

Sabre\HTTP\Response::$status
protected

◆ $statusCodes

Sabre\HTTP\Response::$statusCodes
static
Initial value:
= [
100 => 'Continue'

Definition at line 19 of file Response.php.

Referenced by Sabre\DAV\Xml\Element\Response\xmlSerialize().

◆ $statusText

Sabre\HTTP\Response::$statusText
protected

The documentation for this class was generated from the following file: