框架升级及修复升级后的bug
This commit is contained in:
+208
-212
@@ -64,6 +64,133 @@ class Request
|
||||
public const METHOD_CONNECT = 'CONNECT';
|
||||
public const METHOD_QUERY = 'QUERY';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected static array $trustedProxies = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected static array $trustedHostPatterns = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected static array $trustedHosts = [];
|
||||
|
||||
protected static bool $httpMethodParameterOverride = false;
|
||||
|
||||
/**
|
||||
* The HTTP methods that can be overridden.
|
||||
*
|
||||
* @var uppercase-string[]|null
|
||||
*/
|
||||
protected static ?array $allowedHttpMethodOverride = null;
|
||||
|
||||
/**
|
||||
* Custom parameters.
|
||||
*/
|
||||
public ParameterBag $attributes;
|
||||
|
||||
/**
|
||||
* Request body parameters ($_POST).
|
||||
*
|
||||
* @see getPayload() for portability between content types
|
||||
*/
|
||||
public InputBag $request;
|
||||
|
||||
/**
|
||||
* Query string parameters ($_GET).
|
||||
*
|
||||
* @var InputBag<string>
|
||||
*/
|
||||
public InputBag $query;
|
||||
|
||||
/**
|
||||
* Server and execution environment parameters ($_SERVER).
|
||||
*/
|
||||
public ServerBag $server;
|
||||
|
||||
/**
|
||||
* Uploaded files ($_FILES).
|
||||
*/
|
||||
public FileBag $files;
|
||||
|
||||
/**
|
||||
* Cookies ($_COOKIE).
|
||||
*
|
||||
* @var InputBag<string>
|
||||
*/
|
||||
public InputBag $cookies;
|
||||
|
||||
/**
|
||||
* Headers (taken from the $_SERVER).
|
||||
*/
|
||||
public HeaderBag $headers;
|
||||
|
||||
/**
|
||||
* @var string|resource|false|null
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
/**
|
||||
* @var string[]|null
|
||||
*/
|
||||
protected ?array $languages = null;
|
||||
|
||||
/**
|
||||
* @var string[]|null
|
||||
*/
|
||||
protected ?array $charsets = null;
|
||||
|
||||
/**
|
||||
* @var string[]|null
|
||||
*/
|
||||
protected ?array $encodings = null;
|
||||
|
||||
/**
|
||||
* @var string[]|null
|
||||
*/
|
||||
protected ?array $acceptableContentTypes = null;
|
||||
|
||||
protected ?string $pathInfo = null;
|
||||
protected ?string $requestUri = null;
|
||||
protected ?string $baseUrl = null;
|
||||
protected ?string $basePath = null;
|
||||
protected ?string $method = null;
|
||||
protected ?string $format = null;
|
||||
protected SessionInterface|\Closure|null $session = null;
|
||||
protected ?string $locale = null;
|
||||
protected string $defaultLocale = 'en';
|
||||
|
||||
/**
|
||||
* @var array<string, string[]>|null
|
||||
*/
|
||||
protected static ?array $formats = null;
|
||||
|
||||
protected static ?\Closure $requestFactory = null;
|
||||
|
||||
private ?string $preferredFormat = null;
|
||||
|
||||
private bool $isHostValid = true;
|
||||
private bool $isForwardedValid = true;
|
||||
private bool $isSafeContentPreferred;
|
||||
|
||||
private array $trustedValuesCache = [];
|
||||
|
||||
private static int $trustedHeaderSet = -1;
|
||||
|
||||
/**
|
||||
* @var array<string, true>
|
||||
*/
|
||||
private static array $trustedHostsLiterals = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private static array $trustedHostsRegexps = [];
|
||||
|
||||
private const FORWARDED_PARAMS = [
|
||||
self::HEADER_X_FORWARDED_FOR => 'for',
|
||||
self::HEADER_X_FORWARDED_HOST => 'host',
|
||||
@@ -111,175 +238,6 @@ class Request
|
||||
'yaml' => 'yaml',
|
||||
];
|
||||
|
||||
/**
|
||||
* Custom parameters.
|
||||
*/
|
||||
public ParameterBag $attributes {
|
||||
set {
|
||||
trigger_deprecation('symfony/http-foundation', '8.1', 'Directly setting property "attributes" of "%s" is deprecated; pass attributes as a constructor argument or call "initialize()" instead.', static::class);
|
||||
|
||||
$this->attributes = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request body parameters ($_POST).
|
||||
*
|
||||
* @see getPayload() for portability between content types
|
||||
*/
|
||||
public InputBag $request {
|
||||
set {
|
||||
trigger_deprecation('symfony/http-foundation', '8.1', 'Directly setting property "request" of "%s" is deprecated; pass the POST data as a constructor argument or call "initialize()" instead.', static::class);
|
||||
|
||||
$this->request = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query string parameters ($_GET).
|
||||
*
|
||||
* @var InputBag<string>
|
||||
*/
|
||||
public InputBag $query {
|
||||
set {
|
||||
trigger_deprecation('symfony/http-foundation', '8.1', 'Directly setting property "query" of "%s" is deprecated; pass query parameters as a constructor argument or call "initialize()" instead.', static::class);
|
||||
|
||||
$this->query = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Server and execution environment parameters ($_SERVER).
|
||||
*/
|
||||
public ServerBag $server {
|
||||
set {
|
||||
trigger_deprecation('symfony/http-foundation', '8.1', 'Directly setting property "server" of "%s" is deprecated; pass server parameters as a constructor argument or call "initialize()" instead.', static::class);
|
||||
|
||||
$this->server = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploaded files ($_FILES).
|
||||
*/
|
||||
public FileBag $files {
|
||||
set {
|
||||
trigger_deprecation('symfony/http-foundation', '8.1', 'Directly setting property "files" of "%s" is deprecated; pass files as a constructor argument or call "initialize()" instead.', static::class);
|
||||
|
||||
$this->files = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cookies ($_COOKIE).
|
||||
*
|
||||
* @var InputBag<string>
|
||||
*/
|
||||
public InputBag $cookies {
|
||||
set {
|
||||
trigger_deprecation('symfony/http-foundation', '8.1', 'Directly setting property "cookies" of "%s" is deprecated; pass cookies as a constructor argument or call "initialize()" instead.', static::class);
|
||||
|
||||
$this->cookies = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Headers (taken from the $_SERVER).
|
||||
*/
|
||||
public HeaderBag $headers {
|
||||
set {
|
||||
trigger_deprecation('symfony/http-foundation', '8.1', 'Directly setting property "headers" of "%s" is deprecated; pass header parameters as a constructor argument or call "initialize()" instead.', static::class);
|
||||
|
||||
$this->headers = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @var string|resource|false|null
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
/**
|
||||
* @var string[]|null
|
||||
*/
|
||||
protected ?array $languages = null;
|
||||
|
||||
/**
|
||||
* @var string[]|null
|
||||
*/
|
||||
protected ?array $charsets = null;
|
||||
|
||||
/**
|
||||
* @var string[]|null
|
||||
*/
|
||||
protected ?array $encodings = null;
|
||||
|
||||
/**
|
||||
* @var string[]|null
|
||||
*/
|
||||
protected ?array $acceptableContentTypes = null;
|
||||
|
||||
protected ?string $pathInfo = null;
|
||||
protected ?string $requestUri = null;
|
||||
protected ?string $baseUrl = null;
|
||||
protected ?string $basePath = null;
|
||||
protected ?string $method = null;
|
||||
protected ?string $format = null;
|
||||
protected SessionInterface|\Closure|null $session = null;
|
||||
protected ?string $locale = null;
|
||||
protected string $defaultLocale = 'en';
|
||||
|
||||
/**
|
||||
* @var array<string, string[]>|null
|
||||
*/
|
||||
protected static ?array $formats = null;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected static array $trustedProxies = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected static array $trustedHostPatterns = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected static array $trustedHosts = [];
|
||||
|
||||
protected static bool $httpMethodParameterOverride = false;
|
||||
|
||||
/**
|
||||
* The HTTP methods that can be overridden.
|
||||
*
|
||||
* @var uppercase-string[]|null
|
||||
*/
|
||||
protected static ?array $allowedHttpMethodOverride = null;
|
||||
|
||||
protected static ?\Closure $requestFactory = null;
|
||||
|
||||
private ?string $preferredFormat = null;
|
||||
|
||||
private bool $isHostValid = true;
|
||||
private bool $isForwardedValid = true;
|
||||
private bool $isSafeContentPreferred;
|
||||
|
||||
private array $trustedValuesCache = [];
|
||||
|
||||
private static int $trustedHeaderSet = -1;
|
||||
|
||||
/**
|
||||
* @var array<string, true>
|
||||
*/
|
||||
private static array $trustedHostsLiterals = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private static array $trustedHostsRegexps = [];
|
||||
|
||||
private bool $isIisRewrite = false;
|
||||
|
||||
/**
|
||||
@@ -311,13 +269,13 @@ class Request
|
||||
*/
|
||||
public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = null): void
|
||||
{
|
||||
self::setProperty($this, 'request', new InputBag($request));
|
||||
self::setProperty($this, 'query', new InputBag($query));
|
||||
self::setProperty($this, 'attributes', new ParameterBag($attributes));
|
||||
self::setProperty($this, 'cookies', new InputBag($cookies));
|
||||
self::setProperty($this, 'files', new FileBag($files));
|
||||
self::setProperty($this, 'server', new ServerBag($server));
|
||||
self::setProperty($this, 'headers', new HeaderBag($this->server->getHeaders()));
|
||||
$this->request = new InputBag($request);
|
||||
$this->query = new InputBag($query);
|
||||
$this->attributes = new ParameterBag($attributes);
|
||||
$this->cookies = new InputBag($cookies);
|
||||
$this->files = new FileBag($files);
|
||||
$this->server = new ServerBag($server);
|
||||
$this->headers = new HeaderBag($this->server->getHeaders());
|
||||
|
||||
$this->content = $content;
|
||||
$this->languages = null;
|
||||
@@ -341,8 +299,20 @@ class Request
|
||||
return self::createRequestFromFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER);
|
||||
}
|
||||
|
||||
if (\PHP_VERSION_ID < 80400) {
|
||||
if (!isset($_SERVER['CONTENT_TYPE']) || str_starts_with($_SERVER['CONTENT_TYPE'], 'application/x-www-form-urlencoded')) {
|
||||
$content = file_get_contents('php://input');
|
||||
@parse_str($content, $post);
|
||||
} else {
|
||||
$content = null;
|
||||
$post = $_POST;
|
||||
}
|
||||
|
||||
return self::createRequestFromFactory($_GET, $post, [], $_COOKIE, $_FILES, $_SERVER, $content);
|
||||
}
|
||||
|
||||
try {
|
||||
[$post, $files] = request_parse_body();
|
||||
[$post, $files] = @request_parse_body();
|
||||
} catch (\RequestParseBodyException) {
|
||||
$post = $_POST;
|
||||
$files = $_FILES;
|
||||
@@ -474,7 +444,7 @@ class Request
|
||||
|
||||
$queryString = '';
|
||||
if (isset($components['query'])) {
|
||||
parse_str(html_entity_decode($components['query']), $qs);
|
||||
@parse_str(html_entity_decode($components['query']), $qs);
|
||||
|
||||
if ($query) {
|
||||
$query = array_replace($qs, $query);
|
||||
@@ -519,23 +489,23 @@ class Request
|
||||
{
|
||||
$dup = clone $this;
|
||||
if (null !== $query) {
|
||||
self::setProperty($dup, 'query', new InputBag($query));
|
||||
$dup->query = new InputBag($query);
|
||||
}
|
||||
if (null !== $request) {
|
||||
self::setProperty($dup, 'request', new InputBag($request));
|
||||
$dup->request = new InputBag($request);
|
||||
}
|
||||
if (null !== $attributes) {
|
||||
self::setProperty($dup, 'attributes', new ParameterBag($attributes));
|
||||
$dup->attributes = new ParameterBag($attributes);
|
||||
}
|
||||
if (null !== $cookies) {
|
||||
self::setProperty($dup, 'cookies', new InputBag($cookies));
|
||||
$dup->cookies = new InputBag($cookies);
|
||||
}
|
||||
if (null !== $files) {
|
||||
self::setProperty($dup, 'files', new FileBag($files));
|
||||
$dup->files = new FileBag($files);
|
||||
}
|
||||
if (null !== $server) {
|
||||
self::setProperty($dup, 'server', new ServerBag($server));
|
||||
self::setProperty($dup, 'headers', new HeaderBag($dup->server->getHeaders()));
|
||||
$dup->server = new ServerBag($server);
|
||||
$dup->headers = new HeaderBag($dup->server->getHeaders());
|
||||
}
|
||||
$dup->languages = null;
|
||||
$dup->charsets = null;
|
||||
@@ -567,13 +537,13 @@ class Request
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
self::setProperty($this, 'query', clone $this->query);
|
||||
self::setProperty($this, 'request', clone $this->request);
|
||||
self::setProperty($this, 'attributes', clone $this->attributes);
|
||||
self::setProperty($this, 'cookies', clone $this->cookies);
|
||||
self::setProperty($this, 'files', clone $this->files);
|
||||
self::setProperty($this, 'server', clone $this->server);
|
||||
self::setProperty($this, 'headers', clone $this->headers);
|
||||
$this->query = clone $this->query;
|
||||
$this->request = clone $this->request;
|
||||
$this->attributes = clone $this->attributes;
|
||||
$this->cookies = clone $this->cookies;
|
||||
$this->files = clone $this->files;
|
||||
$this->server = clone $this->server;
|
||||
$this->headers = clone $this->headers;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
@@ -789,6 +759,36 @@ class Request
|
||||
return self::$allowedHttpMethodOverride;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a "parameter" value from any bag.
|
||||
*
|
||||
* This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
|
||||
* flexibility in controllers, it is better to explicitly get request parameters from the appropriate
|
||||
* public property instead (attributes, query, request).
|
||||
*
|
||||
* Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
|
||||
*
|
||||
* @deprecated since Symfony 7.4, use properties `->attributes`, `query` or `request` directly instead
|
||||
*/
|
||||
public function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
trigger_deprecation('symfony/http-foundation', '7.4', 'Request::get() is deprecated, use properties ->attributes, query or request directly instead.');
|
||||
|
||||
if ($this !== $result = $this->attributes->get($key, $this)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($this->query->has($key)) {
|
||||
return $this->query->all()[$key];
|
||||
}
|
||||
|
||||
if ($this->request->has($key)) {
|
||||
return $this->request->all()[$key];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Session.
|
||||
*
|
||||
@@ -1285,7 +1285,7 @@ class Request
|
||||
$method = strtoupper($method);
|
||||
|
||||
if (\in_array($method, ['GET', 'HEAD', 'CONNECT', 'TRACE'], true)) {
|
||||
return $this->method;
|
||||
trigger_deprecation('symfony/http-foundation', '7.4', 'HTTP method override is deprecated for methods GET, HEAD, CONNECT and TRACE; it will be ignored in Symfony 8.0.', $method);
|
||||
}
|
||||
|
||||
if (self::$allowedHttpMethodOverride && !\in_array($method, self::$allowedHttpMethodOverride, true)) {
|
||||
@@ -1350,8 +1350,9 @@ class Request
|
||||
* @param string|null $mimeType The mime type to check
|
||||
* @param bool $subtypeFallback Whether to fall back to the subtype if no exact match is found
|
||||
*/
|
||||
public function getFormat(?string $mimeType, bool $subtypeFallback = false): ?string
|
||||
public function getFormat(?string $mimeType/* , bool $subtypeFallback = false */): ?string
|
||||
{
|
||||
$subtypeFallback = 2 <= \func_num_args() ? func_get_arg(1) : false;
|
||||
$canonicalMimeType = null;
|
||||
if ($mimeType && false !== $pos = strpos($mimeType, ';')) {
|
||||
$canonicalMimeType = trim(substr($mimeType, 0, $pos));
|
||||
@@ -1404,10 +1405,16 @@ class Request
|
||||
/**
|
||||
* Associates a format with mime types.
|
||||
*
|
||||
* @param string $format The format to set
|
||||
* @param string|string[] $mimeTypes The associated mime types (the preferred one must be the first as it will be used as the content type)
|
||||
*/
|
||||
public function setFormat(string $format, string|array $mimeTypes): void
|
||||
public function setFormat(?string $format, string|array $mimeTypes): void
|
||||
{
|
||||
if (null === $format) {
|
||||
trigger_deprecation('symfony/http-foundation', '7.4', 'Passing "null" as the first argument of "%s()" is deprecated. The argument will be non-nullable in Symfony 8.0.', __METHOD__);
|
||||
$format = '';
|
||||
}
|
||||
|
||||
if (null === static::$formats) {
|
||||
static::initializeFormats();
|
||||
}
|
||||
@@ -2213,17 +2220,15 @@ class Request
|
||||
$firstTrustedIp = null;
|
||||
|
||||
foreach ($clientIps as $key => $clientIp) {
|
||||
if (strpos($clientIp, '.')) {
|
||||
// Strip :port from IPv4 addresses. This is allowed in Forwarded
|
||||
// and may occur in X-Forwarded-For.
|
||||
$i = strpos($clientIp, ':');
|
||||
if ($i) {
|
||||
$clientIps[$key] = $clientIp = substr($clientIp, 0, $i);
|
||||
}
|
||||
} elseif (str_starts_with($clientIp, '[')) {
|
||||
if (str_starts_with($clientIp, '[')) {
|
||||
// Strip brackets and :port from IPv6 addresses.
|
||||
$i = strpos($clientIp, ']', 1);
|
||||
$clientIps[$key] = $clientIp = substr($clientIp, 1, $i - 1);
|
||||
} elseif (strpos($clientIp, '.') && 1 === substr_count($clientIp, ':')) {
|
||||
// Strip :port from IPv4 addresses. This is allowed in Forwarded
|
||||
// and may occur in X-Forwarded-For. An IPv6 address with an
|
||||
// embedded IPv4 address has at least two colons and is kept.
|
||||
$clientIps[$key] = $clientIp = strstr($clientIp, ':', true);
|
||||
}
|
||||
|
||||
if (!filter_var($clientIp, \FILTER_VALIDATE_IP)) {
|
||||
@@ -2277,15 +2282,6 @@ class Request
|
||||
return '' === preg_replace('/[-a-zA-Z0-9_]++\.?/', '', $host);
|
||||
}
|
||||
|
||||
private static function setProperty(self $request, string $name, mixed $value): void
|
||||
{
|
||||
static $cache;
|
||||
|
||||
$r = $cache[$name] ??= new \ReflectionProperty(self::class, $name);
|
||||
|
||||
$r->setRawValue($request, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines host patterns into as few regexps as PCRE can compile.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user