框架升级及修复升级后的bug
This commit is contained in:
+18
-26
@@ -105,13 +105,13 @@ class Response
|
||||
'etag' => true,
|
||||
];
|
||||
|
||||
public ResponseHeaderBag $headers {
|
||||
set {
|
||||
trigger_deprecation('symfony/http-foundation', '8.1', 'Directly setting property "headers" of "%s" is deprecated; pass the header bag as a constructor argument instead.', static::class);
|
||||
public ResponseHeaderBag $headers;
|
||||
|
||||
$this->headers = $value;
|
||||
}
|
||||
}
|
||||
protected string $content;
|
||||
protected string $version;
|
||||
protected int $statusCode;
|
||||
protected string $statusText;
|
||||
protected ?string $charset = null;
|
||||
|
||||
/**
|
||||
* Status codes translation table.
|
||||
@@ -189,12 +189,6 @@ class Response
|
||||
511 => 'Network Authentication Required', // RFC6585
|
||||
];
|
||||
|
||||
protected string $content;
|
||||
protected string $version;
|
||||
protected int $statusCode;
|
||||
protected string $statusText;
|
||||
protected ?string $charset = null;
|
||||
|
||||
/**
|
||||
* Tracks headers already sent in informational responses.
|
||||
*/
|
||||
@@ -205,9 +199,9 @@ class Response
|
||||
*
|
||||
* @throws \InvalidArgumentException When the HTTP status code is not valid
|
||||
*/
|
||||
public function __construct(?string $content = '', int $status = 200, array|ResponseHeaderBag $headers = [])
|
||||
public function __construct(?string $content = '', int $status = 200, array $headers = [])
|
||||
{
|
||||
self::setHeaders($this, $headers instanceof ResponseHeaderBag ? $headers : new ResponseHeaderBag($headers));
|
||||
$this->headers = new ResponseHeaderBag($headers);
|
||||
$this->setContent($content);
|
||||
$this->setStatusCode($status);
|
||||
$this->setProtocolVersion('1.0');
|
||||
@@ -235,7 +229,7 @@ class Response
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
self::setHeaders($this, clone $this->headers);
|
||||
$this->headers = clone $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -325,7 +319,8 @@ class Response
|
||||
if (headers_sent()) {
|
||||
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
|
||||
$statusCode ??= $this->statusCode;
|
||||
header(\sprintf('HTTP/%s %s %s', $this->version, $statusCode, $this->statusText), true, $statusCode);
|
||||
trigger_deprecation('symfony/http-foundation', '7.4', 'Trying to use "%s::sendHeaders()" after headers have already been sent is deprecated and will throw a PHP warning in 8.0. Use a "StreamedResponse" instead.', static::class);
|
||||
// header(\sprintf('HTTP/%s %s %s', $this->version, $statusCode, $this->statusText), true, $statusCode);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -486,7 +481,13 @@ class Response
|
||||
throw new \InvalidArgumentException(\sprintf('The HTTP status code "%s" is not valid.', $code));
|
||||
}
|
||||
|
||||
$this->statusText = $text ?? self::$statusTexts[$code] ?? 'unknown status';
|
||||
if (null === $text) {
|
||||
$this->statusText = self::$statusTexts[$code] ?? 'unknown status';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->statusText = $text;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -1319,13 +1320,4 @@ class Response
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function setHeaders(self $response, ResponseHeaderBag $headers): void
|
||||
{
|
||||
static $r;
|
||||
|
||||
$r ??= new \ReflectionProperty(self::class, 'headers');
|
||||
|
||||
$r->setRawValue($response, $headers);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user