京东云

This commit is contained in:
“wanyongkang”
2024-05-28 17:04:50 +08:00
parent f644932afb
commit f3c7432100
672 changed files with 209344 additions and 6593 deletions

View File

@@ -1,7 +1,5 @@
<?php
declare(strict_types=1);
namespace GuzzleHttp\Psr7;
use Psr\Http\Message\ResponseInterface;
@@ -14,8 +12,8 @@ class Response implements ResponseInterface
{
use MessageTrait;
/** Map of standard HTTP status code/reason phrases */
private const PHRASES = [
/** @var array Map of standard HTTP status code/reason phrases */
private static $phrases = [
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
@@ -36,7 +34,6 @@ class Response implements ResponseInterface
305 => 'Use Proxy',
306 => 'Switch Proxy',
307 => 'Temporary Redirect',
308 => 'Permanent Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
@@ -74,30 +71,31 @@ class Response implements ResponseInterface
506 => 'Variant Also Negotiates',
507 => 'Insufficient Storage',
508 => 'Loop Detected',
510 => 'Not Extended',
511 => 'Network Authentication Required',
];
/** @var string */
private $reasonPhrase;
private $reasonPhrase = '';
/** @var int */
private $statusCode;
private $statusCode = 200;
/**
* @param int $status Status code
* @param (string|string[])[] $headers Response headers
* @param array $headers Response headers
* @param string|resource|StreamInterface|null $body Response body
* @param string $version Protocol version
* @param string|null $reason Reason phrase (when empty a default will be used based on the status code)
*/
public function __construct(
int $status = 200,
$status = 200,
array $headers = [],
$body = null,
string $version = '1.1',
string $reason = null
$version = '1.1',
$reason = null
) {
$this->assertStatusCodeIsInteger($status);
$status = (int) $status;
$this->assertStatusCodeRange($status);
$this->statusCode = $status;
@@ -107,8 +105,8 @@ class Response implements ResponseInterface
}
$this->setHeaders($headers);
if ($reason == '' && isset(self::PHRASES[$this->statusCode])) {
$this->reasonPhrase = self::PHRASES[$this->statusCode];
if ($reason == '' && isset(self::$phrases[$this->statusCode])) {
$this->reasonPhrase = self::$phrases[$this->statusCode];
} else {
$this->reasonPhrase = (string) $reason;
}
@@ -116,17 +114,17 @@ class Response implements ResponseInterface
$this->protocol = $version;
}
public function getStatusCode(): int
public function getStatusCode()
{
return $this->statusCode;
}
public function getReasonPhrase(): string
public function getReasonPhrase()
{
return $this->reasonPhrase;
}
public function withStatus($code, $reasonPhrase = ''): ResponseInterface
public function withStatus($code, $reasonPhrase = '')
{
$this->assertStatusCodeIsInteger($code);
$code = (int) $code;
@@ -134,25 +132,21 @@ class Response implements ResponseInterface
$new = clone $this;
$new->statusCode = $code;
if ($reasonPhrase == '' && isset(self::PHRASES[$new->statusCode])) {
$reasonPhrase = self::PHRASES[$new->statusCode];
if ($reasonPhrase == '' && isset(self::$phrases[$new->statusCode])) {
$reasonPhrase = self::$phrases[$new->statusCode];
}
$new->reasonPhrase = (string) $reasonPhrase;
return $new;
}
/**
* @param mixed $statusCode
*/
private function assertStatusCodeIsInteger($statusCode): void
private function assertStatusCodeIsInteger($statusCode)
{
if (filter_var($statusCode, FILTER_VALIDATE_INT) === false) {
throw new \InvalidArgumentException('Status code must be an integer value.');
}
}
private function assertStatusCodeRange(int $statusCode): void
private function assertStatusCodeRange($statusCode)
{
if ($statusCode < 100 || $statusCode >= 600) {
throw new \InvalidArgumentException('Status code must be an integer value between 1xx and 5xx.');