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

This is the abstract base class for both the Request and Response objects. More...

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

Public Member Functions

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

Protected Attributes

 $body
 
 $headers = []
 
 $httpVersion = '1.1'
 

Detailed Description

This is the abstract base class for both the Request and Response objects.

This object contains a few simple methods that are shared by both.

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

Definition at line 14 of file Message.php.

Member Function Documentation

◆ addHeader()

Sabre\HTTP\Message::addHeader (   $name,
  $value 
)

Adds a HTTP header.

This method will not overwrite any existing HTTP header, but instead add another value. Individual values can be retrieved with getHeadersAsArray.

Parameters
string$name
string$value
Returns
void

Implements Sabre\HTTP\MessageInterface.

Definition at line 235 of file Message.php.

References $name.

Referenced by Sabre\HTTP\Message\addHeaders().

235  {
236 
237  $lName = strtolower($name);
238  if (isset($this->headers[$lName])) {
239  $this->headers[$lName][1] = array_merge(
240  $this->headers[$lName][1],
241  (array)$value
242  );
243  } else {
244  $this->headers[$lName] = [
245  $name,
246  (array)$value
247  ];
248  }
249 
250  }
+ Here is the caller graph for this function:

◆ addHeaders()

Sabre\HTTP\Message::addHeaders ( array  $headers)

Adds a new set of HTTP headers.

Any existing headers will not be overwritten.

Parameters
array$headers
Returns
void

Implements Sabre\HTTP\MessageInterface.

Definition at line 260 of file Message.php.

References $name, and Sabre\HTTP\Message\addHeader().

260  {
261 
262  foreach ($headers as $name => $value) {
263  $this->addHeader($name, $value);
264  }
265 
266  }
addHeader($name, $value)
Adds a HTTP header.
Definition: Message.php:235
+ Here is the call graph for this function:

◆ getBody()

Sabre\HTTP\Message::getBody ( )

Returns the message body, as it's internal representation.

This could be either a string or a stream.

Returns
resource|string

Implements Sabre\HTTP\MessageInterface.

Definition at line 92 of file Message.php.

References Sabre\HTTP\Message\$body.

Referenced by Sabre\HTTP\Message\getBodyAsStream(), and Sabre\HTTP\Message\getBodyAsString().

92  {
93 
94  return $this->body;
95 
96  }
+ Here is the caller graph for this function:

◆ getBodyAsStream()

Sabre\HTTP\Message::getBodyAsStream ( )

Returns the body as a readable stream resource.

Note that the stream may not be rewindable, and therefore may only be read once.

Returns
resource

Implements Sabre\HTTP\MessageInterface.

Definition at line 47 of file Message.php.

References Sabre\HTTP\Message\$body, GuzzleHttp\Psr7\$stream, and Sabre\HTTP\Message\getBody().

47  {
48 
49  $body = $this->getBody();
50  if (is_string($body) || is_null($body)) {
51  $stream = fopen('php://temp', 'r+');
52  fwrite($stream, $body);
53  rewind($stream);
54  return $stream;
55  }
56  return $body;
57 
58  }
$stream
PHP stream implementation.
getBody()
Returns the message body, as it's internal representation.
Definition: Message.php:92
+ Here is the call graph for this function:

◆ getBodyAsString()

Sabre\HTTP\Message::getBodyAsString ( )

Returns the body as a string.

Note that because the underlying data may be based on a stream, this method could only work correctly the first time.

Returns
string

Implements Sabre\HTTP\MessageInterface.

Definition at line 68 of file Message.php.

References Sabre\HTTP\Message\$body, $contentLength, Sabre\HTTP\Message\getBody(), and Sabre\HTTP\Message\getHeader().

Referenced by Sabre\HTTP\Response\__toString(), Sabre\HTTP\Request\__toString(), and Sabre\DAV\Locks\Plugin2Test\testUnlockAfterDelete().

68  {
69 
70  $body = $this->getBody();
71  if (is_string($body)) {
72  return $body;
73  }
74  if (is_null($body)) {
75  return '';
76  }
77  $contentLength = $this->getHeader('Content-Length');
78  if (is_int($contentLength) || ctype_digit($contentLength)) {
79  return stream_get_contents($body, $contentLength);
80  } else {
81  return stream_get_contents($body);
82  }
83  }
if(preg_match('#\.( $contentLength[^/\.]+)$#D', $path, $type)) if($contentType===null)
Definition: module.php:165
getHeader($name)
Returns a specific HTTP header, based on it's name.
Definition: Message.php:154
getBody()
Returns the message body, as it's internal representation.
Definition: Message.php:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHeader()

Sabre\HTTP\Message::getHeader (   $name)

Returns a specific HTTP header, based on it's name.

The name must be treated as case-insensitive. If the header does not exist, this method must return null.

If a header appeared more than once in a HTTP request, this method will concatenate all the values with a comma.

Note that this not make sense for all headers. Some, such as Set-Cookie cannot be logically combined with a comma. In those cases you should use getHeaderAsArray().

Parameters
string$name
Returns
string|null

Implements Sabre\HTTP\MessageInterface.

Definition at line 154 of file Message.php.

References $name.

Referenced by Sabre\HTTP\Message\getBodyAsString().

154  {
155 
156  $name = strtolower($name);
157 
158  if (isset($this->headers[$name])) {
159  return implode(',', $this->headers[$name][1]);
160  }
161  return null;
162 
163  }
+ Here is the caller graph for this function:

◆ getHeaderAsArray()

Sabre\HTTP\Message::getHeaderAsArray (   $name)

Returns a HTTP header as an array.

For every time the HTTP header appeared in the request or response, an item will appear in the array.

If the header did not exists, this method will return an empty array.

Parameters
string$name
Returns
string[]

Implements Sabre\HTTP\MessageInterface.

Definition at line 176 of file Message.php.

References $name.

176  {
177 
178  $name = strtolower($name);
179 
180  if (isset($this->headers[$name])) {
181  return $this->headers[$name][1];
182  }
183 
184  return [];
185 
186  }

◆ getHeaders()

Sabre\HTTP\Message::getHeaders ( )

Returns all the HTTP headers as an array.

Every header is returned as an array, with one or more values.

Returns
array

Implements Sabre\HTTP\MessageInterface.

Definition at line 116 of file Message.php.

References $result.

Referenced by Sabre\HTTP\Response\__toString(), and Sabre\HTTP\Request\__toString().

116  {
117 
118  $result = [];
119  foreach ($this->headers as $headerInfo) {
120  $result[$headerInfo[0]] = $headerInfo[1];
121  }
122  return $result;
123 
124  }
$result
+ Here is the caller graph for this function:

◆ getHttpVersion()

Sabre\HTTP\Message::getHttpVersion ( )

Returns the HTTP version.

Returns
string

Implements Sabre\HTTP\MessageInterface.

Definition at line 309 of file Message.php.

References Sabre\HTTP\Message\$httpVersion.

309  {
310 
311  return $this->httpVersion;
312 
313  }

◆ hasHeader()

Sabre\HTTP\Message::hasHeader (   $name)

Will return true or false, depending on if a HTTP header exists.

Parameters
string$name
Returns
bool

Implements Sabre\HTTP\MessageInterface.

Definition at line 132 of file Message.php.

References $name.

132  {
133 
134  return isset($this->headers[strtolower($name)]);
135 
136  }

◆ removeHeader()

Sabre\HTTP\Message::removeHeader (   $name)

Removes a HTTP header.

The specified header name must be treated as case-insensitive. This method should return true if the header was successfully deleted, and false if the header did not exist.

Parameters
string$name
Returns
bool

Implements Sabre\HTTP\MessageInterface.

Definition at line 279 of file Message.php.

References $name.

279  {
280 
281  $name = strtolower($name);
282  if (!isset($this->headers[$name])) {
283  return false;
284  }
285  unset($this->headers[$name]);
286  return true;
287 
288  }

◆ setBody()

Sabre\HTTP\Message::setBody (   $body)

Replaces the body resource with a new stream or string.

Parameters
resource | string$body

Implements Sabre\HTTP\MessageInterface.

Definition at line 103 of file Message.php.

References Sabre\HTTP\Message\$body.

Referenced by Sabre\HTTP\Request\__construct(), and Sabre\HTTP\Response\__construct().

103  {
104 
105  $this->body = $body;
106 
107  }
+ Here is the caller graph for this function:

◆ setHeader()

Sabre\HTTP\Message::setHeader (   $name,
  $value 
)

Updates a HTTP header.

The case-sensitivity of the name value must be retained as-is.

If the header already existed, it will be overwritten.

Parameters
string$name
string|string[]$value
Returns
void

Implements Sabre\HTTP\MessageInterface.

Definition at line 199 of file Message.php.

References $name.

Referenced by Sabre\HTTP\Message\setHeaders().

199  {
200 
201  $this->headers[strtolower($name)] = [$name, (array)$value];
202 
203  }
+ Here is the caller graph for this function:

◆ setHeaders()

Sabre\HTTP\Message::setHeaders ( array  $headers)

Sets a new set of HTTP headers.

The headers array should contain headernames for keys, and their value should be specified as either a string or an array.

Any header that already existed will be overwritten.

Parameters
array$headers
Returns
void

Implements Sabre\HTTP\MessageInterface.

Definition at line 216 of file Message.php.

References $name, and Sabre\HTTP\Message\setHeader().

Referenced by Sabre\HTTP\Request\__construct(), and Sabre\HTTP\Response\__construct().

216  {
217 
218  foreach ($headers as $name => $value) {
219  $this->setHeader($name, $value);
220  }
221 
222  }
setHeader($name, $value)
Updates a HTTP header.
Definition: Message.php:199
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHttpVersion()

Sabre\HTTP\Message::setHttpVersion (   $version)

Sets the HTTP version.

Should be 1.0 or 1.1.

Parameters
string$version
Returns
void

Implements Sabre\HTTP\MessageInterface.

Definition at line 298 of file Message.php.

References $version.

298  {
299 
300  $this->httpVersion = $version;
301 
302  }
$version
Definition: build.php:27

Field Documentation

◆ $body

◆ $headers

Sabre\HTTP\Message::$headers = []
protected

Definition at line 30 of file Message.php.

Referenced by Sabre\HTTP\Request\__construct(), and Sabre\HTTP\Response\__construct().

◆ $httpVersion

Sabre\HTTP\Message::$httpVersion = '1.1'
protected

Definition at line 37 of file Message.php.

Referenced by Sabre\HTTP\Message\getHttpVersion().


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