aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/http/lib/Response.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/http/lib/Response.php')
-rw-r--r--vendor/sabre/http/lib/Response.php75
1 files changed, 35 insertions, 40 deletions
diff --git a/vendor/sabre/http/lib/Response.php b/vendor/sabre/http/lib/Response.php
index 01920d8d9..64dfbc0b2 100644
--- a/vendor/sabre/http/lib/Response.php
+++ b/vendor/sabre/http/lib/Response.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
namespace Sabre\HTTP;
/**
@@ -9,14 +11,14 @@ namespace Sabre\HTTP;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class Response extends Message implements ResponseInterface {
-
+class Response extends Message implements ResponseInterface
+{
/**
* This is the list of currently registered HTTP status codes.
*
* @var array
*/
- static $statusCodes = [
+ public static $statusCodes = [
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
@@ -81,57 +83,55 @@ class Response extends Message implements ResponseInterface {
];
/**
- * HTTP status code
+ * HTTP status code.
*
* @var int
*/
protected $status;
/**
- * HTTP status text
+ * HTTP status text.
*
* @var string
*/
protected $statusText;
/**
- * Creates the response object
+ * Creates the response object.
*
* @param string|int $status
- * @param array $headers
- * @param resource $body
+ * @param array $headers
+ * @param resource $body
*/
- function __construct($status = null, array $headers = null, $body = null) {
-
- if (!is_null($status)) $this->setStatus($status);
- if (!is_null($headers)) $this->setHeaders($headers);
- if (!is_null($body)) $this->setBody($body);
-
+ public function __construct($status = 500, array $headers = null, $body = null)
+ {
+ if (null !== $status) {
+ $this->setStatus($status);
+ }
+ if (null !== $headers) {
+ $this->setHeaders($headers);
+ }
+ if (null !== $body) {
+ $this->setBody($body);
+ }
}
-
/**
* Returns the current HTTP status code.
- *
- * @return int
*/
- function getStatus() {
-
+ public function getStatus(): int
+ {
return $this->status;
-
}
/**
* Returns the human-readable status string.
*
* In the case of a 200, this may for example be 'OK'.
- *
- * @return string
*/
- function getStatusText() {
-
+ public function getStatusText(): string
+ {
return $this->statusText;
-
}
/**
@@ -144,21 +144,20 @@ class Response extends Message implements ResponseInterface {
* added.
*
* @param string|int $status
+ *
* @throws \InvalidArgumentException
- * @return void
*/
- function setStatus($status) {
-
+ public function setStatus($status)
+ {
if (ctype_digit($status) || is_int($status)) {
-
$statusCode = $status;
- $statusText = isset(self::$statusCodes[$status]) ? self::$statusCodes[$status] : 'Unknown';
-
+ $statusText = self::$statusCodes[$status] ?? 'Unknown';
} else {
list(
$statusCode,
$statusText
) = explode(' ', $status, 2);
+ $statusCode = (int) $statusCode;
}
if ($statusCode < 100 || $statusCode > 999) {
throw new \InvalidArgumentException('The HTTP status code must be exactly 3 digits');
@@ -166,28 +165,24 @@ class Response extends Message implements ResponseInterface {
$this->status = $statusCode;
$this->statusText = $statusText;
-
}
/**
* Serializes the response object as a string.
*
* This is useful for debugging purposes.
- *
- * @return string
*/
- function __toString() {
-
- $str = 'HTTP/' . $this->httpVersion . ' ' . $this->getStatus() . ' ' . $this->getStatusText() . "\r\n";
+ public function __toString(): string
+ {
+ $str = 'HTTP/'.$this->httpVersion.' '.$this->getStatus().' '.$this->getStatusText()."\r\n";
foreach ($this->getHeaders() as $key => $value) {
foreach ($value as $v) {
- $str .= $key . ": " . $v . "\r\n";
+ $str .= $key.': '.$v."\r\n";
}
}
$str .= "\r\n";
$str .= $this->getBodyAsString();
- return $str;
+ return $str;
}
-
}