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

@@ -34,12 +34,9 @@ class JsonResponse extends Response
protected $encodingOptions = self::DEFAULT_ENCODING_OPTIONS;
/**
* @param mixed $data The response data
* @param int $status The response status code
* @param array $headers An array of response headers
* @param bool $json If the data is already a JSON string
* @param bool $json If the data is already a JSON string
*/
public function __construct($data = null, int $status = 200, array $headers = [], bool $json = false)
public function __construct(mixed $data = null, int $status = 200, array $headers = [], bool $json = false)
{
parent::__construct('', $status, $headers);
@@ -54,29 +51,6 @@ class JsonResponse extends Response
$json ? $this->setJson($data) : $this->setData($data);
}
/**
* Factory method for chainability.
*
* Example:
*
* return JsonResponse::create(['key' => 'value'])
* ->setSharedMaxAge(300);
*
* @param mixed $data The JSON response data
* @param int $status The response status code
* @param array $headers An array of response headers
*
* @return static
*
* @deprecated since Symfony 5.1, use __construct() instead.
*/
public static function create($data = null, 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($data, $status, $headers);
}
/**
* Factory method for chainability.
*
@@ -88,10 +62,8 @@ class JsonResponse extends Response
* @param string $data The JSON response string
* @param int $status The response status code
* @param array $headers An array of response headers
*
* @return static
*/
public static function fromJsonString(string $data, int $status = 200, array $headers = [])
public static function fromJsonString(string $data, int $status = 200, array $headers = []): static
{
return new static($data, $status, $headers, true);
}
@@ -105,7 +77,7 @@ class JsonResponse extends Response
*
* @throws \InvalidArgumentException When the callback name is not valid
*/
public function setCallback(string $callback = null)
public function setCallback(string $callback = null): static
{
if (null !== $callback) {
// partially taken from https://geekality.net/2011/08/03/valid-javascript-identifier/
@@ -136,7 +108,7 @@ class JsonResponse extends Response
*
* @return $this
*/
public function setJson(string $json)
public function setJson(string $json): static
{
$this->data = $json;
@@ -146,13 +118,11 @@ class JsonResponse extends Response
/**
* Sets the data to be sent as JSON.
*
* @param mixed $data
*
* @return $this
*
* @throws \InvalidArgumentException
*/
public function setData($data = [])
public function setData(mixed $data = []): static
{
try {
$data = json_encode($data, $this->encodingOptions);
@@ -163,7 +133,7 @@ class JsonResponse extends Response
throw $e;
}
if (\PHP_VERSION_ID >= 70300 && (\JSON_THROW_ON_ERROR & $this->encodingOptions)) {
if (\JSON_THROW_ON_ERROR & $this->encodingOptions) {
return $this->setJson($data);
}
@@ -176,10 +146,8 @@ class JsonResponse extends Response
/**
* Returns options used while encoding data to JSON.
*
* @return int
*/
public function getEncodingOptions()
public function getEncodingOptions(): int
{
return $this->encodingOptions;
}
@@ -189,7 +157,7 @@ class JsonResponse extends Response
*
* @return $this
*/
public function setEncodingOptions(int $encodingOptions)
public function setEncodingOptions(int $encodingOptions): static
{
$this->encodingOptions = $encodingOptions;
@@ -201,7 +169,7 @@ class JsonResponse extends Response
*
* @return $this
*/
protected function update()
protected function update(): static
{
if (null !== $this->callback) {
// Not using application/javascript for compatibility reasons with older browsers.