ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Request.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\HTTP;
4 
6 use Sabre\Uri;
7 
18 class Request extends Message implements RequestInterface {
19 
25  protected $method;
26 
32  protected $url;
33 
42  function __construct($method = null, $url = null, array $headers = null, $body = null) {
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  }
53 
59  function getMethod() {
60 
61  return $this->method;
62 
63  }
64 
71  function setMethod($method) {
72 
73  $this->method = $method;
74 
75  }
76 
82  function getUrl() {
83 
84  return $this->url;
85 
86  }
87 
94  function setUrl($url) {
95 
96  $this->url = $url;
97 
98  }
99 
107  function getQueryParameters() {
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  }
118 
125  function setAbsoluteUrl($url) {
126 
127  $this->absoluteUrl = $url;
128 
129  }
130 
136  function getAbsoluteUrl() {
137 
138  return $this->absoluteUrl;
139 
140  }
141 
147  protected $baseUrl = '/';
148 
157  function setBaseUrl($url) {
158 
159  $this->baseUrl = $url;
160 
161  }
162 
168  function getBaseUrl() {
169 
170  return $this->baseUrl;
171 
172  }
173 
191  function getPath() {
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  }
216 
222  protected $postData = [];
223 
235  function setPostData(array $postData) {
236 
237  $this->postData = $postData;
238 
239  }
240 
248  function getPostData() {
249 
250  return $this->postData;
251 
252  }
253 
259  protected $rawServerData;
260 
269  function getRawServerValue($valueName) {
270 
271  if (isset($this->rawServerData[$valueName])) {
272  return $this->rawServerData[$valueName];
273  }
274 
275  }
276 
283  function setRawServerData(array $data) {
284 
285  $this->rawServerData = $data;
286 
287  }
288 
296  function __toString() {
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  }
315 
316 }
getPath()
Returns the relative path.
Definition: Request.php:191
The RequestInterface represents a HTTP request.
This is the abstract base class for both the Request and Response objects.
Definition: Message.php:14
The Request class represents a single HTTP request.
Definition: Request.php:18
setBaseUrl($url)
Sets a base url.
Definition: Request.php:157
getRawServerValue($valueName)
Returns an item from the _SERVER array.
Definition: Request.php:269
setMethod($method)
Sets the HTTP method.
Definition: Request.php:71
setAbsoluteUrl($url)
Sets the absolute url.
Definition: Request.php:125
$index
Definition: metadata.php:60
getBaseUrl()
Returns the current base url.
Definition: Request.php:168
setBody($body)
Replaces the body resource with a new stream or string.
Definition: Message.php:103
getAbsoluteUrl()
Returns the absolute url.
Definition: Request.php:136
getHeaders()
Returns all the HTTP headers as an array.
Definition: Message.php:116
getBodyAsString()
Returns the body as a string.
Definition: Message.php:68
static decodePath($path)
Decodes a url-encoded path.
Definition: URLUtil.php:57
getQueryParameters()
Returns the list of query parameters.
Definition: Request.php:107
setPostData(array $postData)
Sets the post data.
Definition: Request.php:235
setUrl($url)
Sets the request url.
Definition: Request.php:94
setHeaders(array $headers)
Sets a new set of HTTP headers.
Definition: Message.php:216
__construct($method=null, $url=null, array $headers=null, $body=null)
Creates the request object.
Definition: Request.php:42
getPostData()
Returns the POST data.
Definition: Request.php:248
getMethod()
Returns the current HTTP method.
Definition: Request.php:59
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
$key
Definition: croninfo.php:18
setRawServerData(array $data)
Sets the _SERVER array.
Definition: Request.php:283
__toString()
Serializes the request object as a string.
Definition: Request.php:296
$data
Definition: bench.php:6