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

The Request class represents a single HTTP request. More...

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

Public Member Functions

 __construct ($method=null, $url=null, array $headers=null, $body=null)
 Creates the request object. More...
 
 getMethod ()
 Returns the current HTTP method. More...
 
 setMethod ($method)
 Sets the HTTP method. More...
 
 getUrl ()
 Returns the request url. More...
 
 setUrl ($url)
 Sets the request url. More...
 
 getQueryParameters ()
 Returns the list of query parameters. More...
 
 setAbsoluteUrl ($url)
 Sets the absolute url. More...
 
 getAbsoluteUrl ()
 Returns the absolute url. More...
 
 setBaseUrl ($url)
 Sets a base url. More...
 
 getBaseUrl ()
 Returns the current base url. More...
 
 getPath ()
 Returns the relative path. More...
 
 setPostData (array $postData)
 Sets the post data. More...
 
 getPostData ()
 Returns the POST data. More...
 
 getRawServerValue ($valueName)
 Returns an item from the _SERVER array. More...
 
 setRawServerData (array $data)
 Sets the _SERVER array. More...
 
 __toString ()
 Serializes the request 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...
 

Protected Attributes

 $method
 
 $url
 
 $baseUrl = '/'
 
 $postData = []
 
 $rawServerData
 
- Protected Attributes inherited from Sabre\HTTP\Message
 $body
 
 $headers = []
 
 $httpVersion = '1.1'
 

Detailed Description

The Request class represents a single HTTP request.

You can either simply construct the object from scratch, or if you need access to the current HTTP request, use Sapi::getRequest.

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

Definition at line 18 of file Request.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\HTTP\Request::__construct (   $method = null,
  $url = null,
array  $headers = null,
  $body = null 
)

Creates the request object.

Parameters
string$method
string$url
array$headers
resource$body

Definition at line 42 of file Request.php.

References Sabre\HTTP\Message\$body, Sabre\HTTP\Message\$headers, Sabre\HTTP\Request\$method, Sabre\HTTP\Request\$url, Sabre\HTTP\Message\setBody(), Sabre\HTTP\Message\setHeaders(), Sabre\HTTP\Request\setMethod(), and Sabre\HTTP\Request\setUrl().

42  {
43 
44  if (is_array($method)) {
45  throw new InvalidArgumentException('The first argument for this constructor should be a string or null, not an array. Did you upgrade from sabre/http 1.0 to 2.0?');
46  }
47  if (!is_null($method)) $this->setMethod($method);
48  if (!is_null($url)) $this->setUrl($url);
49  if (!is_null($headers)) $this->setHeaders($headers);
50  if (!is_null($body)) $this->setBody($body);
51 
52  }
setMethod($method)
Sets the HTTP method.
Definition: Request.php:71
setBody($body)
Replaces the body resource with a new stream or string.
Definition: Message.php:103
setUrl($url)
Sets the request url.
Definition: Request.php:94
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\Request::__toString ( )

Serializes the request object as a string.

This is useful for debugging purposes.

Returns
string

Definition at line 296 of file Request.php.

References $key, $out, Sabre\HTTP\Message\getBodyAsString(), Sabre\HTTP\Message\getHeaders(), Sabre\HTTP\Request\getMethod(), and Sabre\HTTP\Request\getUrl().

296  {
297 
298  $out = $this->getMethod() . ' ' . $this->getUrl() . ' HTTP/' . $this->getHTTPVersion() . "\r\n";
299 
300  foreach ($this->getHeaders() as $key => $value) {
301  foreach ($value as $v) {
302  if ($key === 'Authorization') {
303  list($v) = explode(' ', $v, 2);
304  $v .= ' REDACTED';
305  }
306  $out .= $key . ": " . $v . "\r\n";
307  }
308  }
309  $out .= "\r\n";
310  $out .= $this->getBodyAsString();
311 
312  return $out;
313 
314  }
getHeaders()
Returns all the HTTP headers as an array.
Definition: Message.php:116
getBodyAsString()
Returns the body as a string.
Definition: Message.php:68
getMethod()
Returns the current HTTP method.
Definition: Request.php:59
getUrl()
Returns the request url.
Definition: Request.php:82
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ getAbsoluteUrl()

Sabre\HTTP\Request::getAbsoluteUrl ( )

Returns the absolute url.

Returns
string

Implements Sabre\HTTP\RequestInterface.

Definition at line 136 of file Request.php.

136  {
137 
138  return $this->absoluteUrl;
139 
140  }

◆ getBaseUrl()

Sabre\HTTP\Request::getBaseUrl ( )

Returns the current base url.

Returns
string

Implements Sabre\HTTP\RequestInterface.

Definition at line 168 of file Request.php.

References Sabre\HTTP\Request\$baseUrl.

Referenced by Sabre\HTTP\Request\getPath().

168  {
169 
170  return $this->baseUrl;
171 
172  }
+ Here is the caller graph for this function:

◆ getMethod()

Sabre\HTTP\Request::getMethod ( )

Returns the current HTTP method.

Returns
string

Implements Sabre\HTTP\RequestInterface.

Definition at line 59 of file Request.php.

References Sabre\HTTP\Request\$method.

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

59  {
60 
61  return $this->method;
62 
63  }
+ Here is the caller graph for this function:

◆ getPath()

Sabre\HTTP\Request::getPath ( )

Returns the relative path.

This is being calculated using the base url. This path will not start with a slash, so it will always return something like 'example/path.html'.

If the full path is equal to the base url, this method will return an empty string.

This method will also urldecode the path, and if the url was incoded as ISO-8859-1, it will convert it to UTF-8.

If the path is outside of the base url, a LogicException will be thrown.

Returns
string

Implements Sabre\HTTP\RequestInterface.

Definition at line 191 of file Request.php.

References $baseUri, Sabre\HTTP\URLUtil\decodePath(), Sabre\HTTP\Request\getBaseUrl(), Sabre\HTTP\Request\getUrl(), and Sabre\Uri\normalize().

191  {
192 
193  // Removing duplicated slashes.
194  $uri = str_replace('//', '/', $this->getUrl());
195 
196  $uri = Uri\normalize($uri);
197  $baseUri = Uri\normalize($this->getBaseUrl());
198 
199  if (strpos($uri, $baseUri) === 0) {
200 
201  // We're not interested in the query part (everything after the ?).
202  list($uri) = explode('?', $uri);
203  return trim(URLUtil::decodePath(substr($uri, strlen($baseUri))), '/');
204 
205  }
206  // A special case, if the baseUri was accessed without a trailing
207  // slash, we'll accept it as well.
208  elseif ($uri . '/' === $baseUri) {
209 
210  return '';
211 
212  }
213 
214  throw new \LogicException('Requested uri (' . $this->getUrl() . ') is out of base uri (' . $this->getBaseUrl() . ')');
215  }
getBaseUrl()
Returns the current base url.
Definition: Request.php:168
static decodePath($path)
Decodes a url-encoded path.
Definition: URLUtil.php:57
getUrl()
Returns the request url.
Definition: Request.php:82
normalize($uri)
Takes a URI or partial URI as its argument, and normalizes it.
Definition: functions.php:114
+ Here is the call graph for this function:

◆ getPostData()

Sabre\HTTP\Request::getPostData ( )

Returns the POST data.

This is equivalent to PHP's $_POST superglobal.

Returns
array

Implements Sabre\HTTP\RequestInterface.

Definition at line 248 of file Request.php.

References Sabre\HTTP\Request\$postData.

248  {
249 
250  return $this->postData;
251 
252  }

◆ getQueryParameters()

Sabre\HTTP\Request::getQueryParameters ( )

Returns the list of query parameters.

This is equivalent to PHP's $_GET superglobal.

Returns
array

Implements Sabre\HTTP\RequestInterface.

Definition at line 107 of file Request.php.

References $index, Sabre\HTTP\Request\$url, and Sabre\HTTP\Request\getUrl().

107  {
108 
109  $url = $this->getUrl();
110  if (($index = strpos($url, '?')) === false) {
111  return [];
112  } else {
113  parse_str(substr($url, $index + 1), $queryParams);
114  return $queryParams;
115  }
116 
117  }
$index
Definition: metadata.php:60
getUrl()
Returns the request url.
Definition: Request.php:82
+ Here is the call graph for this function:

◆ getRawServerValue()

Sabre\HTTP\Request::getRawServerValue (   $valueName)

Returns an item from the _SERVER array.

If the value does not exist in the array, null is returned.

Parameters
string$valueName
Returns
string|null

Implements Sabre\HTTP\RequestInterface.

Definition at line 269 of file Request.php.

269  {
270 
271  if (isset($this->rawServerData[$valueName])) {
272  return $this->rawServerData[$valueName];
273  }
274 
275  }

◆ getUrl()

Sabre\HTTP\Request::getUrl ( )

Returns the request url.

Returns
string

Implements Sabre\HTTP\RequestInterface.

Definition at line 82 of file Request.php.

References Sabre\HTTP\Request\$url.

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

82  {
83 
84  return $this->url;
85 
86  }
+ Here is the caller graph for this function:

◆ setAbsoluteUrl()

Sabre\HTTP\Request::setAbsoluteUrl (   $url)

Sets the absolute url.

Parameters
string$url
Returns
void

Implements Sabre\HTTP\RequestInterface.

Definition at line 125 of file Request.php.

References Sabre\HTTP\Request\$url.

125  {
126 
127  $this->absoluteUrl = $url;
128 
129  }

◆ setBaseUrl()

Sabre\HTTP\Request::setBaseUrl (   $url)

Sets a base url.

This url is used for relative path calculations.

Parameters
string$url
Returns
void

Implements Sabre\HTTP\RequestInterface.

Definition at line 157 of file Request.php.

References Sabre\HTTP\Request\$url.

157  {
158 
159  $this->baseUrl = $url;
160 
161  }

◆ setMethod()

Sabre\HTTP\Request::setMethod (   $method)

Sets the HTTP method.

Parameters
string$method
Returns
void

Implements Sabre\HTTP\RequestInterface.

Definition at line 71 of file Request.php.

References Sabre\HTTP\Request\$method.

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

71  {
72 
73  $this->method = $method;
74 
75  }
+ Here is the caller graph for this function:

◆ setPostData()

Sabre\HTTP\Request::setPostData ( array  $postData)

Sets the post data.

This is equivalent to PHP's $_POST superglobal.

This would not have been needed, if POST data was accessible as php://input, but unfortunately we need to special case it.

Parameters
array$postData
Returns
void

Implements Sabre\HTTP\RequestInterface.

Definition at line 235 of file Request.php.

References Sabre\HTTP\Request\$postData.

235  {
236 
237  $this->postData = $postData;
238 
239  }

◆ setRawServerData()

Sabre\HTTP\Request::setRawServerData ( array  $data)

Sets the _SERVER array.

Parameters
array$data
Returns
void

Implements Sabre\HTTP\RequestInterface.

Definition at line 283 of file Request.php.

References $data.

283  {
284 
285  $this->rawServerData = $data;
286 
287  }
$data
Definition: bench.php:6

◆ setUrl()

Sabre\HTTP\Request::setUrl (   $url)

Sets the request url.

Parameters
string$url
Returns
void

Implements Sabre\HTTP\RequestInterface.

Definition at line 94 of file Request.php.

References Sabre\HTTP\Request\$url.

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

94  {
95 
96  $this->url = $url;
97 
98  }
+ Here is the caller graph for this function:

Field Documentation

◆ $baseUrl

Sabre\HTTP\Request::$baseUrl = '/'
protected

Definition at line 147 of file Request.php.

Referenced by Sabre\HTTP\Request\getBaseUrl().

◆ $method

Sabre\HTTP\Request::$method
protected

◆ $postData

Sabre\HTTP\Request::$postData = []
protected

Definition at line 222 of file Request.php.

Referenced by Sabre\HTTP\Request\getPostData(), and Sabre\HTTP\Request\setPostData().

◆ $rawServerData

Sabre\HTTP\Request::$rawServerData
protected

Definition at line 259 of file Request.php.

◆ $url


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