aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/http/lib/Request.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/http/lib/Request.php')
-rw-r--r--vendor/sabre/http/lib/Request.php189
1 files changed, 70 insertions, 119 deletions
diff --git a/vendor/sabre/http/lib/Request.php b/vendor/sabre/http/lib/Request.php
index dfa3d5b48..496629a5b 100644
--- a/vendor/sabre/http/lib/Request.php
+++ b/vendor/sabre/http/lib/Request.php
@@ -1,8 +1,10 @@
<?php
+declare(strict_types=1);
+
namespace Sabre\HTTP;
-use InvalidArgumentException;
+use LogicException;
use Sabre\Uri;
/**
@@ -15,132 +17,111 @@ use Sabre\Uri;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class Request extends Message implements RequestInterface {
-
+class Request extends Message implements RequestInterface
+{
/**
- * HTTP Method
+ * HTTP Method.
*
* @var string
*/
protected $method;
/**
- * Request Url
+ * Request Url.
*
* @var string
*/
protected $url;
/**
- * Creates the request object
+ * Creates the request object.
*
- * @param string $method
- * @param string $url
- * @param array $headers
- * @param resource $body
+ * @param resource|callable|string $body
*/
- function __construct($method = null, $url = null, array $headers = null, $body = null) {
-
- if (is_array($method)) {
- 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?');
- }
- if (!is_null($method)) $this->setMethod($method);
- if (!is_null($url)) $this->setUrl($url);
- if (!is_null($headers)) $this->setHeaders($headers);
- if (!is_null($body)) $this->setBody($body);
-
+ public function __construct(string $method, string $url, array $headers = [], $body = null)
+ {
+ $this->setMethod($method);
+ $this->setUrl($url);
+ $this->setHeaders($headers);
+ $this->setBody($body);
}
/**
- * Returns the current HTTP method
- *
- * @return string
+ * Returns the current HTTP method.
*/
- function getMethod() {
-
+ public function getMethod(): string
+ {
return $this->method;
-
}
/**
- * Sets the HTTP method
- *
- * @param string $method
- * @return void
+ * Sets the HTTP method.
*/
- function setMethod($method) {
-
+ public function setMethod(string $method)
+ {
$this->method = $method;
-
}
/**
* Returns the request url.
- *
- * @return string
*/
- function getUrl() {
-
+ public function getUrl(): string
+ {
return $this->url;
-
}
/**
* Sets the request url.
- *
- * @param string $url
- * @return void
*/
- function setUrl($url) {
-
+ public function setUrl(string $url)
+ {
$this->url = $url;
-
}
/**
* Returns the list of query parameters.
*
* This is equivalent to PHP's $_GET superglobal.
- *
- * @return array
*/
- function getQueryParameters() {
-
+ public function getQueryParameters(): array
+ {
$url = $this->getUrl();
- if (($index = strpos($url, '?')) === false) {
+ if (false === ($index = strpos($url, '?'))) {
return [];
- } else {
- parse_str(substr($url, $index + 1), $queryParams);
- return $queryParams;
}
+ parse_str(substr($url, $index + 1), $queryParams);
+
+ return $queryParams;
}
+ protected $absoluteUrl;
+
/**
* Sets the absolute url.
- *
- * @param string $url
- * @return void
*/
- function setAbsoluteUrl($url) {
-
+ public function setAbsoluteUrl(string $url)
+ {
$this->absoluteUrl = $url;
-
}
/**
* Returns the absolute url.
- *
- * @return string
*/
- function getAbsoluteUrl() {
+ public function getAbsoluteUrl(): string
+ {
+ if (!$this->absoluteUrl) {
+ // Guessing we're a http endpoint.
+ $this->absoluteUrl = 'http://'.
+ ($this->getHeader('Host') ?? 'localhost').
+ $this->getUrl();
+ }
return $this->absoluteUrl;
-
}
/**
- * Base url
+ * Base url.
*
* @var string
*/
@@ -150,25 +131,18 @@ class Request extends Message implements RequestInterface {
* Sets a base url.
*
* This url is used for relative path calculations.
- *
- * @param string $url
- * @return void
*/
- function setBaseUrl($url) {
-
+ public function setBaseUrl(string $url)
+ {
$this->baseUrl = $url;
-
}
/**
* Returns the current base url.
- *
- * @return string
*/
- function getBaseUrl() {
-
+ public function getBaseUrl(): string
+ {
return $this->baseUrl;
-
}
/**
@@ -185,33 +159,29 @@ class Request extends Message implements RequestInterface {
* ISO-8859-1, it will convert it to UTF-8.
*
* If the path is outside of the base url, a LogicException will be thrown.
- *
- * @return string
*/
- function getPath() {
-
+ public function getPath(): string
+ {
// Removing duplicated slashes.
$uri = str_replace('//', '/', $this->getUrl());
$uri = Uri\normalize($uri);
$baseUri = Uri\normalize($this->getBaseUrl());
- if (strpos($uri, $baseUri) === 0) {
-
+ if (0 === strpos($uri, $baseUri)) {
// We're not interested in the query part (everything after the ?).
list($uri) = explode('?', $uri);
- return trim(URLUtil::decodePath(substr($uri, strlen($baseUri))), '/');
+ return trim(decodePath(substr($uri, strlen($baseUri))), '/');
}
- // A special case, if the baseUri was accessed without a trailing
- // slash, we'll accept it as well.
- elseif ($uri . '/' === $baseUri) {
+ if ($uri.'/' === $baseUri) {
return '';
-
}
+ // A special case, if the baseUri was accessed without a trailing
+ // slash, we'll accept it as well.
- throw new \LogicException('Requested uri (' . $this->getUrl() . ') is out of base uri (' . $this->getBaseUrl() . ')');
+ throw new \LogicException('Requested uri ('.$this->getUrl().') is out of base uri ('.$this->getBaseUrl().')');
}
/**
@@ -228,27 +198,20 @@ class Request extends Message implements RequestInterface {
*
* This would not have been needed, if POST data was accessible as
* php://input, but unfortunately we need to special case it.
- *
- * @param array $postData
- * @return void
*/
- function setPostData(array $postData) {
-
+ public function setPostData(array $postData)
+ {
$this->postData = $postData;
-
}
/**
* Returns the POST data.
*
* This is equivalent to PHP's $_POST superglobal.
- *
- * @return array
*/
- function getPostData() {
-
+ public function getPostData(): array
+ {
return $this->postData;
-
}
/**
@@ -263,54 +226,42 @@ class Request extends Message implements RequestInterface {
*
* If the value does not exist in the array, null is returned.
*
- * @param string $valueName
* @return string|null
*/
- function getRawServerValue($valueName) {
-
- if (isset($this->rawServerData[$valueName])) {
- return $this->rawServerData[$valueName];
- }
-
+ public function getRawServerValue(string $valueName)
+ {
+ return $this->rawServerData[$valueName] ?? null;
}
/**
* Sets the _SERVER array.
- *
- * @param array $data
- * @return void
*/
- function setRawServerData(array $data) {
-
+ public function setRawServerData(array $data)
+ {
$this->rawServerData = $data;
-
}
/**
* Serializes the request object as a string.
*
* This is useful for debugging purposes.
- *
- * @return string
*/
- function __toString() {
-
- $out = $this->getMethod() . ' ' . $this->getUrl() . ' HTTP/' . $this->getHTTPVersion() . "\r\n";
+ public function __toString(): string
+ {
+ $out = $this->getMethod().' '.$this->getUrl().' HTTP/'.$this->getHttpVersion()."\r\n";
foreach ($this->getHeaders() as $key => $value) {
foreach ($value as $v) {
- if ($key === 'Authorization') {
+ if ('Authorization' === $key) {
list($v) = explode(' ', $v, 2);
$v .= ' REDACTED';
}
- $out .= $key . ": " . $v . "\r\n";
+ $out .= $key.': '.$v."\r\n";
}
}
$out .= "\r\n";
$out .= $this->getBodyAsString();
return $out;
-
}
-
}