fix:更新已知bug,优化代码

This commit is contained in:
Ying
2022-11-28 19:11:12 +08:00
parent f6aee95cfc
commit 9445b206a2
1378 changed files with 53759 additions and 20789 deletions

View File

@@ -220,25 +220,6 @@ class Response
$this->setProtocolVersion('1.0');
}
/**
* Factory method for chainability.
*
* Example:
*
* return Response::create($body, 200)
* ->setSharedMaxAge(300);
*
* @return static
*
* @deprecated since Symfony 5.1, use __construct() instead.
*/
public static function create(?string $content = '', int $status = 200, array $headers = [])
{
trigger_deprecation('symfony/http-foundation', '5.1', 'The "%s()" method is deprecated, use "new %s()" instead.', __METHOD__, static::class);
return new static($content, $status, $headers);
}
/**
* Returns the Response as an HTTP string.
*
@@ -246,11 +227,9 @@ class Response
* one that will be sent to the client only if the prepare() method
* has been called before.
*
* @return string
*
* @see prepare()
*/
public function __toString()
public function __toString(): string
{
return
sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n".
@@ -275,7 +254,7 @@ class Response
*
* @return $this
*/
public function prepare(Request $request)
public function prepare(Request $request): static
{
$headers = $this->headers;
@@ -345,7 +324,7 @@ class Response
*
* @return $this
*/
public function sendHeaders()
public function sendHeaders(): static
{
// headers have already been sent by the developer
if (headers_sent()) {
@@ -376,7 +355,7 @@ class Response
*
* @return $this
*/
public function sendContent()
public function sendContent(): static
{
echo $this->content;
@@ -388,7 +367,7 @@ class Response
*
* @return $this
*/
public function send()
public function send(): static
{
$this->sendHeaders();
$this->sendContent();
@@ -399,6 +378,7 @@ class Response
litespeed_finish_request();
} elseif (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
static::closeOutputBuffers(0, true);
flush();
}
return $this;
@@ -409,7 +389,7 @@ class Response
*
* @return $this
*/
public function setContent(?string $content)
public function setContent(?string $content): static
{
$this->content = $content ?? '';
@@ -418,10 +398,8 @@ class Response
/**
* Gets the current response content.
*
* @return string|false
*/
public function getContent()
public function getContent(): string|false
{
return $this->content;
}
@@ -433,7 +411,7 @@ class Response
*
* @final
*/
public function setProtocolVersion(string $version): object
public function setProtocolVersion(string $version): static
{
$this->version = $version;
@@ -462,7 +440,7 @@ class Response
*
* @final
*/
public function setStatusCode(int $code, string $text = null): object
public function setStatusCode(int $code, string $text = null): static
{
$this->statusCode = $code;
if ($this->isInvalid()) {
@@ -503,7 +481,7 @@ class Response
*
* @final
*/
public function setCharset(string $charset): object
public function setCharset(string $charset): static
{
$this->charset = $charset;
@@ -584,7 +562,7 @@ class Response
*
* @final
*/
public function setPrivate(): object
public function setPrivate(): static
{
$this->headers->removeCacheControlDirective('public');
$this->headers->addCacheControlDirective('private');
@@ -601,7 +579,7 @@ class Response
*
* @final
*/
public function setPublic(): object
public function setPublic(): static
{
$this->headers->addCacheControlDirective('public');
$this->headers->removeCacheControlDirective('private');
@@ -616,7 +594,7 @@ class Response
*
* @final
*/
public function setImmutable(bool $immutable = true): object
public function setImmutable(bool $immutable = true): static
{
if ($immutable) {
$this->headers->addCacheControlDirective('immutable');
@@ -671,7 +649,7 @@ class Response
*
* @final
*/
public function setDate(\DateTimeInterface $date): object
public function setDate(\DateTimeInterface $date): static
{
if ($date instanceof \DateTime) {
$date = \DateTimeImmutable::createFromMutable($date);
@@ -702,7 +680,7 @@ class Response
*
* @return $this
*/
public function expire()
public function expire(): static
{
if ($this->isFresh()) {
$this->headers->set('Age', $this->getMaxAge());
@@ -736,7 +714,7 @@ class Response
*
* @final
*/
public function setExpires(\DateTimeInterface $date = null): object
public function setExpires(\DateTimeInterface $date = null): static
{
if (null === $date) {
$this->headers->remove('Expires');
@@ -789,7 +767,7 @@ class Response
*
* @final
*/
public function setMaxAge(int $value): object
public function setMaxAge(int $value): static
{
$this->headers->addCacheControlDirective('max-age', $value);
@@ -805,7 +783,7 @@ class Response
*
* @final
*/
public function setSharedMaxAge(int $value): object
public function setSharedMaxAge(int $value): static
{
$this->setPublic();
$this->headers->addCacheControlDirective('s-maxage', $value);
@@ -839,7 +817,7 @@ class Response
*
* @final
*/
public function setTtl(int $seconds): object
public function setTtl(int $seconds): static
{
$this->setSharedMaxAge($this->getAge() + $seconds);
@@ -855,7 +833,7 @@ class Response
*
* @final
*/
public function setClientTtl(int $seconds): object
public function setClientTtl(int $seconds): static
{
$this->setMaxAge($this->getAge() + $seconds);
@@ -883,7 +861,7 @@ class Response
*
* @final
*/
public function setLastModified(\DateTimeInterface $date = null): object
public function setLastModified(\DateTimeInterface $date = null): static
{
if (null === $date) {
$this->headers->remove('Last-Modified');
@@ -921,7 +899,7 @@ class Response
*
* @final
*/
public function setEtag(string $etag = null, bool $weak = false): object
public function setEtag(string $etag = null, bool $weak = false): static
{
if (null === $etag) {
$this->headers->remove('Etag');
@@ -947,7 +925,7 @@ class Response
*
* @final
*/
public function setCache(array $options): object
public function setCache(array $options): static
{
if ($diff = array_diff(array_keys($options), array_keys(self::HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES))) {
throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', $diff)));
@@ -1010,7 +988,7 @@ class Response
*
* @final
*/
public function setNotModified(): object
public function setNotModified(): static
{
$this->setStatusCode(304);
$this->setContent(null);
@@ -1055,14 +1033,13 @@ class Response
/**
* Sets the Vary header.
*
* @param string|array $headers
* @param bool $replace Whether to replace the actual value or not (true by default)
* @param bool $replace Whether to replace the actual value or not (true by default)
*
* @return $this
*
* @final
*/
public function setVary($headers, bool $replace = true): object
public function setVary(string|array $headers, bool $replace = true): static
{
$this->headers->set('Vary', $headers, $replace);
@@ -1245,7 +1222,6 @@ class Response
while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || ($s['flags'] & $flags) === $flags : $s['del'])) {
if ($flush) {
ob_end_flush();
flush();
} else {
ob_end_clean();
}