upgraded dependencies

This commit is contained in:
RafficMohammed
2023-01-08 01:59:16 +05:30
parent 51056e3aad
commit f9ae387337
6895 changed files with 133617 additions and 178680 deletions

View File

@@ -12,6 +12,8 @@
namespace Symfony\Component\HttpFoundation;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpFoundation\Exception\JsonException;
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
@@ -20,6 +22,7 @@ class_exists(AcceptHeader::class);
class_exists(FileBag::class);
class_exists(HeaderBag::class);
class_exists(HeaderUtils::class);
class_exists(InputBag::class);
class_exists(ParameterBag::class);
class_exists(ServerBag::class);
@@ -38,13 +41,17 @@ class_exists(ServerBag::class);
*/
class Request
{
public const HEADER_FORWARDED = 0b00001; // When using RFC 7239
public const HEADER_X_FORWARDED_FOR = 0b00010;
public const HEADER_X_FORWARDED_HOST = 0b00100;
public const HEADER_X_FORWARDED_PROTO = 0b01000;
public const HEADER_X_FORWARDED_PORT = 0b10000;
public const HEADER_X_FORWARDED_ALL = 0b11110; // All "X-Forwarded-*" headers
public const HEADER_X_FORWARDED_AWS_ELB = 0b11010; // AWS ELB doesn't send X-Forwarded-Host
public const HEADER_FORWARDED = 0b000001; // When using RFC 7239
public const HEADER_X_FORWARDED_FOR = 0b000010;
public const HEADER_X_FORWARDED_HOST = 0b000100;
public const HEADER_X_FORWARDED_PROTO = 0b001000;
public const HEADER_X_FORWARDED_PORT = 0b010000;
public const HEADER_X_FORWARDED_PREFIX = 0b100000;
/** @deprecated since Symfony 5.2, use either "HEADER_X_FORWARDED_FOR | HEADER_X_FORWARDED_HOST | HEADER_X_FORWARDED_PORT | HEADER_X_FORWARDED_PROTO" or "HEADER_X_FORWARDED_AWS_ELB" or "HEADER_X_FORWARDED_TRAEFIK" constants instead. */
public const HEADER_X_FORWARDED_ALL = 0b1011110; // All "X-Forwarded-*" headers sent by "usual" reverse proxy
public const HEADER_X_FORWARDED_AWS_ELB = 0b0011010; // AWS ELB doesn't send X-Forwarded-Host
public const HEADER_X_FORWARDED_TRAEFIK = 0b0111110; // All "X-Forwarded-*" headers sent by Traefik reverse proxy
public const METHOD_HEAD = 'HEAD';
public const METHOD_GET = 'GET';
@@ -84,14 +91,14 @@ class Request
/**
* Request body parameters ($_POST).
*
* @var ParameterBag
* @var InputBag
*/
public $request;
/**
* Query string parameters ($_GET).
*
* @var ParameterBag
* @var InputBag
*/
public $query;
@@ -112,7 +119,7 @@ class Request
/**
* Cookies ($_COOKIE).
*
* @var ParameterBag
* @var InputBag
*/
public $cookies;
@@ -179,7 +186,7 @@ class Request
protected $format;
/**
* @var SessionInterface|callable
* @var SessionInterface|callable(): SessionInterface
*/
protected $session;
@@ -207,6 +214,11 @@ class Request
private $isHostValid = true;
private $isForwardedValid = true;
/**
* @var bool|null
*/
private $isSafeContentPreferred;
private static $trustedHeaderSet = -1;
private const FORWARDED_PARAMS = [
@@ -231,6 +243,7 @@ class Request
self::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
self::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
self::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
self::HEADER_X_FORWARDED_PREFIX => 'X_FORWARDED_PREFIX',
];
/**
@@ -262,10 +275,10 @@ class Request
*/
public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = null)
{
$this->request = new ParameterBag($request);
$this->query = new ParameterBag($query);
$this->request = new InputBag($request);
$this->query = new InputBag($query);
$this->attributes = new ParameterBag($attributes);
$this->cookies = new ParameterBag($cookies);
$this->cookies = new InputBag($cookies);
$this->files = new FileBag($files);
$this->server = new ServerBag($server);
$this->headers = new HeaderBag($this->server->getHeaders());
@@ -296,7 +309,7 @@ class Request
&& \in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])
) {
parse_str($request->getContent(), $data);
$request->request = new ParameterBag($data);
$request->request = new InputBag($data);
}
return $request;
@@ -318,7 +331,7 @@ class Request
*
* @return static
*/
public static function create($uri, $method = 'GET', $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
public static function create(string $uri, string $method = 'GET', array $parameters = [], array $cookies = [], array $files = [], array $server = [], $content = null)
{
$server = array_replace([
'SERVER_NAME' => 'localhost',
@@ -417,10 +430,8 @@ class Request
* This is mainly useful when you need to override the Request class
* to keep BC with an existing system. It should not be used for any
* other purpose.
*
* @param callable|null $callable A PHP callable
*/
public static function setFactory($callable)
public static function setFactory(?callable $callable)
{
self::$requestFactory = $callable;
}
@@ -441,16 +452,16 @@ class Request
{
$dup = clone $this;
if (null !== $query) {
$dup->query = new ParameterBag($query);
$dup->query = new InputBag($query);
}
if (null !== $request) {
$dup->request = new ParameterBag($request);
$dup->request = new InputBag($request);
}
if (null !== $attributes) {
$dup->attributes = new ParameterBag($attributes);
}
if (null !== $cookies) {
$dup->cookies = new ParameterBag($cookies);
$dup->cookies = new InputBag($cookies);
}
if (null !== $files) {
$dup->files = new FileBag($files);
@@ -501,7 +512,7 @@ class Request
/**
* Returns the request as a string.
*
* @return string The request
* @return string
*/
public function __toString()
{
@@ -511,10 +522,10 @@ class Request
$cookies = [];
foreach ($this->cookies as $k => $v) {
$cookies[] = $k.'='.$v;
$cookies[] = \is_array($v) ? http_build_query([$k => $v], '', '; ', \PHP_QUERY_RFC3986) : "$k=$v";
}
if (!empty($cookies)) {
if ($cookies) {
$cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n";
}
@@ -573,6 +584,9 @@ class Request
*/
public static function setTrustedProxies(array $proxies, int $trustedHeaderSet)
{
if (self::HEADER_X_FORWARDED_ALL === $trustedHeaderSet) {
trigger_deprecation('symfony/http-foundation', '5.2', 'The "HEADER_X_FORWARDED_ALL" constant is deprecated, use either "HEADER_X_FORWARDED_FOR | HEADER_X_FORWARDED_HOST | HEADER_X_FORWARDED_PORT | HEADER_X_FORWARDED_PROTO" or "HEADER_X_FORWARDED_AWS_ELB" or "HEADER_X_FORWARDED_TRAEFIK" constants instead.');
}
self::$trustedProxies = array_reduce($proxies, function ($proxies, $proxy) {
if ('REMOTE_ADDR' !== $proxy) {
$proxies[] = $proxy;
@@ -588,7 +602,7 @@ class Request
/**
* Gets the list of trusted proxies.
*
* @return array An array of trusted proxies
* @return array
*/
public static function getTrustedProxies()
{
@@ -624,7 +638,7 @@ class Request
/**
* Gets the list of trusted host patterns.
*
* @return array An array of trusted host patterns
* @return array
*/
public static function getTrustedHosts()
{
@@ -637,17 +651,15 @@ class Request
* It builds a normalized query string, where keys/value pairs are alphabetized,
* have consistent escaping and unneeded delimiters are removed.
*
* @param string $qs Query string
*
* @return string A normalized query string for the Request
* @return string
*/
public static function normalizeQueryString($qs)
public static function normalizeQueryString(?string $qs)
{
if ('' === ($qs ?? '')) {
return '';
}
parse_str($qs, $qs);
$qs = HeaderUtils::parseQuery($qs);
ksort($qs);
return http_build_query($qs, '', '&', \PHP_QUERY_RFC3986);
@@ -672,7 +684,7 @@ class Request
/**
* Checks whether support for the _method request parameter is enabled.
*
* @return bool True when the _method request parameter is enabled, false otherwise
* @return bool
*/
public static function getHttpMethodParameterOverride()
{
@@ -688,23 +700,24 @@ class Request
*
* Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
*
* @param string $key The key
* @param mixed $default The default value if the parameter key does not exist
* @param mixed $default The default value if the parameter key does not exist
*
* @return mixed
*
* @internal since Symfony 5.4, use explicit input sources instead
*/
public function get($key, $default = null)
public function get(string $key, $default = null)
{
if ($this !== $result = $this->attributes->get($key, $this)) {
return $result;
}
if ($this !== $result = $this->query->get($key, $this)) {
return $result;
if ($this->query->has($key)) {
return $this->query->all()[$key];
}
if ($this !== $result = $this->request->get($key, $this)) {
return $result;
if ($this->request->has($key)) {
return $this->request->all()[$key];
}
return $default;
@@ -713,7 +726,7 @@ class Request
/**
* Gets the Session.
*
* @return SessionInterface The session
* @return SessionInterface
*/
public function getSession()
{
@@ -723,8 +736,7 @@ class Request
}
if (null === $session) {
@trigger_error(sprintf('Calling "%s()" when no session has been set is deprecated since Symfony 4.1 and will throw an exception in 5.0. Use "hasSession()" instead.', __METHOD__), \E_USER_DEPRECATED);
// throw new \BadMethodCallException('Session has not been set.');
throw new SessionNotFoundException('Session has not been set.');
}
return $session;
@@ -749,11 +761,15 @@ class Request
* like whether the session is started or not. It is just a way to check if this Request
* is associated with a Session instance.
*
* @return bool true when the Request contains a Session object, false otherwise
* @param bool $skipIfUninitialized When true, ignores factories injected by `setSessionFactory`
*
* @return bool
*/
public function hasSession()
public function hasSession(/* bool $skipIfUninitialized = false */)
{
return null !== $this->session;
$skipIfUninitialized = \func_num_args() > 0 ? func_get_arg(0) : false;
return null !== $this->session && (!$skipIfUninitialized || $this->session instanceof SessionInterface);
}
public function setSession(SessionInterface $session)
@@ -763,6 +779,8 @@ class Request
/**
* @internal
*
* @param callable(): SessionInterface $factory
*/
public function setSessionFactory(callable $factory)
{
@@ -778,7 +796,7 @@ class Request
*
* Use this method carefully; you should use getClientIp() instead.
*
* @return array The client IP addresses
* @return array
*
* @see getClientIp()
*/
@@ -806,7 +824,7 @@ class Request
* ("Client-Ip" for instance), configure it via the $trustedHeaderSet
* argument of the Request::setTrustedProxies() method instead.
*
* @return string|null The client IP address
* @return string|null
*
* @see getClientIps()
* @see https://wikipedia.org/wiki/X-Forwarded-For
@@ -883,6 +901,24 @@ class Request
* @return string The raw URL (i.e. not urldecoded)
*/
public function getBaseUrl()
{
$trustedPrefix = '';
// the proxy prefix must be prepended to any prefix being needed at the webserver level
if ($this->isFromTrustedProxy() && $trustedPrefixValues = $this->getTrustedValues(self::HEADER_X_FORWARDED_PREFIX)) {
$trustedPrefix = rtrim($trustedPrefixValues[0], '/');
}
return $trustedPrefix.$this->getBaseUrlReal();
}
/**
* Returns the real base URL received by the webserver from which this request is executed.
* The URL does not include trusted reverse proxy prefix.
*
* @return string The raw URL (i.e. not urldecoded)
*/
private function getBaseUrlReal(): string
{
if (null === $this->baseUrl) {
$this->baseUrl = $this->prepareBaseUrl();
@@ -909,7 +945,7 @@ class Request
*
* The "X-Forwarded-Port" header must contain the client port.
*
* @return int|string can be a string if fetched from the server bag
* @return int|string|null Can be a string if fetched from the server bag
*/
public function getPort()
{
@@ -1010,7 +1046,7 @@ class Request
* If the URL was called with basic authentication, the user
* and the password are not added to the generated string.
*
* @return string The scheme and HTTP host
* @return string
*/
public function getSchemeAndHttpHost()
{
@@ -1020,7 +1056,7 @@ class Request
/**
* Generates a normalized URI (URL) for the Request.
*
* @return string A normalized URI (URL) for the Request
* @return string
*
* @see getQueryString()
*/
@@ -1038,9 +1074,9 @@ class Request
*
* @param string $path A path to use instead of the current one
*
* @return string The normalized URI for the path
* @return string
*/
public function getUriForPath($path)
public function getUriForPath(string $path)
{
return $this->getSchemeAndHttpHost().$this->getBaseUrl().$path;
}
@@ -1060,11 +1096,9 @@ class Request
* - "/a/b/c/other" -> "other"
* - "/a/x/y" -> "../../x/y"
*
* @param string $path The target path
*
* @return string The relative target path
* @return string
*/
public function getRelativeUriForPath($path)
public function getRelativeUriForPath(string $path)
{
// be sure that we are dealing with an absolute path
if (!isset($path[0]) || '/' !== $path[0]) {
@@ -1106,7 +1140,7 @@ class Request
* It builds a normalized query string, where keys/value pairs are alphabetized
* and have consistent escaping.
*
* @return string|null A normalized query string for the Request
* @return string|null
*/
public function getQueryString()
{
@@ -1202,10 +1236,8 @@ class Request
/**
* Sets the request method.
*
* @param string $method
*/
public function setMethod($method)
public function setMethod(string $method)
{
$this->method = null;
$this->server->set('REQUEST_METHOD', $method);
@@ -1222,7 +1254,7 @@ class Request
*
* The method is always an uppercased string.
*
* @return string The request method
* @return string
*
* @see getRealMethod()
*/
@@ -1264,7 +1296,7 @@ class Request
/**
* Gets the "real" request method.
*
* @return string The request method
* @return string
*
* @see getMethod()
*/
@@ -1276,11 +1308,9 @@ class Request
/**
* Gets the mime type associated with the format.
*
* @param string $format The format
*
* @return string|null The associated mime type (null if not found)
* @return string|null
*/
public function getMimeType($format)
public function getMimeType(string $format)
{
if (null === static::$formats) {
static::initializeFormats();
@@ -1292,11 +1322,9 @@ class Request
/**
* Gets the mime types associated with the format.
*
* @param string $format The format
*
* @return array The associated mime types
* @return array
*/
public static function getMimeTypes($format)
public static function getMimeTypes(string $format)
{
if (null === static::$formats) {
static::initializeFormats();
@@ -1308,14 +1336,12 @@ class Request
/**
* Gets the format associated with the mime type.
*
* @param string $mimeType The associated mime type
*
* @return string|null The format (null if not found)
* @return string|null
*/
public function getFormat($mimeType)
public function getFormat(?string $mimeType)
{
$canonicalMimeType = null;
if (false !== $pos = strpos($mimeType, ';')) {
if ($mimeType && false !== $pos = strpos($mimeType, ';')) {
$canonicalMimeType = trim(substr($mimeType, 0, $pos));
}
@@ -1338,10 +1364,9 @@ class Request
/**
* Associates a format with mime types.
*
* @param string $format The format
* @param string|array $mimeTypes The associated mime types (the preferred one must be the first as it will be used as the content type)
*/
public function setFormat($format, $mimeTypes)
public function setFormat(?string $format, $mimeTypes)
{
if (null === static::$formats) {
static::initializeFormats();
@@ -1361,11 +1386,9 @@ class Request
*
* @see getPreferredFormat
*
* @param string|null $default The default format
*
* @return string|null The request format
* @return string|null
*/
public function getRequestFormat($default = 'html')
public function getRequestFormat(?string $default = 'html')
{
if (null === $this->format) {
$this->format = $this->attributes->get('_format');
@@ -1376,10 +1399,8 @@ class Request
/**
* Sets the request format.
*
* @param string $format The request format
*/
public function setRequestFormat($format)
public function setRequestFormat(?string $format)
{
$this->format = $format;
}
@@ -1387,7 +1408,7 @@ class Request
/**
* Gets the format associated with the request.
*
* @return string|null The format (null if no content type is present)
* @return string|null
*/
public function getContentType()
{
@@ -1396,10 +1417,8 @@ class Request
/**
* Sets the default locale.
*
* @param string $locale
*/
public function setDefaultLocale($locale)
public function setDefaultLocale(string $locale)
{
$this->defaultLocale = $locale;
@@ -1420,10 +1439,8 @@ class Request
/**
* Sets the locale.
*
* @param string $locale
*/
public function setLocale($locale)
public function setLocale(string $locale)
{
$this->setPhpDefaultLocale($this->locale = $locale);
}
@@ -1445,7 +1462,7 @@ class Request
*
* @return bool
*/
public function isMethod($method)
public function isMethod(string $method)
{
return $this->getMethod() === strtoupper($method);
}
@@ -1459,10 +1476,6 @@ class Request
*/
public function isMethodSafe()
{
if (\func_num_args() > 0) {
@trigger_error(sprintf('Passing arguments to "%s()" has been deprecated since Symfony 4.4; use "%s::isMethodCacheable()" to check if the method is cacheable instead.', __METHOD__, __CLASS__), \E_USER_DEPRECATED);
}
return \in_array($this->getMethod(), ['GET', 'HEAD', 'OPTIONS', 'TRACE']);
}
@@ -1481,7 +1494,7 @@ class Request
*
* @see https://tools.ietf.org/html/rfc7231#section-4.2.3
*
* @return bool True for GET and HEAD, false otherwise
* @return bool
*/
public function isMethodCacheable()
{
@@ -1517,9 +1530,9 @@ class Request
*
* @param bool $asResource If true, a resource will be returned
*
* @return string|resource The request body content or a resource to read the body stream
* @return string|resource
*/
public function getContent($asResource = false)
public function getContent(bool $asResource = false)
{
$currentContentIsResource = \is_resource($this->content);
@@ -1557,10 +1570,40 @@ class Request
return $this->content;
}
/**
* Gets the request body decoded as array, typically from a JSON payload.
*
* @throws JsonException When the body cannot be decoded to an array
*
* @return array
*/
public function toArray()
{
if ('' === $content = $this->getContent()) {
throw new JsonException('Request body is empty.');
}
try {
$content = json_decode($content, true, 512, \JSON_BIGINT_AS_STRING | (\PHP_VERSION_ID >= 70300 ? \JSON_THROW_ON_ERROR : 0));
} catch (\JsonException $e) {
throw new JsonException('Could not decode request body.', $e->getCode(), $e);
}
if (\PHP_VERSION_ID < 70300 && \JSON_ERROR_NONE !== json_last_error()) {
throw new JsonException('Could not decode request body: '.json_last_error_msg(), json_last_error());
}
if (!\is_array($content)) {
throw new JsonException(sprintf('JSON content was expected to decode to an array, "%s" returned.', get_debug_type($content)));
}
return $content;
}
/**
* Gets the Etags.
*
* @return array The entity tags
* @return array
*/
public function getETags()
{
@@ -1577,7 +1620,7 @@ class Request
/**
* Gets the preferred format for the response by inspecting, in the following order:
* * the request format set using setRequestFormat
* * the request format set using setRequestFormat;
* * the values of the Accept HTTP header.
*
* Note that if you use this method, you should send the "Vary: Accept" header
@@ -1603,7 +1646,7 @@ class Request
*
* @param string[] $locales An array of ordered available locales
*
* @return string|null The preferred locale
* @return string|null
*/
public function getPreferredLanguage(array $locales = null)
{
@@ -1634,9 +1677,9 @@ class Request
}
/**
* Gets a list of languages acceptable by the client browser.
* Gets a list of languages acceptable by the client browser ordered in the user browser preferences.
*
* @return array Languages ordered in the user browser preferences
* @return array
*/
public function getLanguages()
{
@@ -1675,9 +1718,9 @@ class Request
}
/**
* Gets a list of charsets acceptable by the client browser.
* Gets a list of charsets acceptable by the client browser in preferable order.
*
* @return array List of charsets in preferable order
* @return array
*/
public function getCharsets()
{
@@ -1689,9 +1732,9 @@ class Request
}
/**
* Gets a list of encodings acceptable by the client browser.
* Gets a list of encodings acceptable by the client browser in preferable order.
*
* @return array List of encodings in preferable order
* @return array
*/
public function getEncodings()
{
@@ -1703,9 +1746,9 @@ class Request
}
/**
* Gets a list of content types acceptable by the client browser.
* Gets a list of content types acceptable by the client browser in preferable order.
*
* @return array List of content types in preferable order
* @return array
*/
public function getAcceptableContentTypes()
{
@@ -1724,13 +1767,32 @@ class Request
*
* @see https://wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript
*
* @return bool true if the request is an XMLHttpRequest, false otherwise
* @return bool
*/
public function isXmlHttpRequest()
{
return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
}
/**
* Checks whether the client browser prefers safe content or not according to RFC8674.
*
* @see https://tools.ietf.org/html/rfc8674
*/
public function preferSafeContent(): bool
{
if (null !== $this->isSafeContentPreferred) {
return $this->isSafeContentPreferred;
}
if (!$this->isSecure()) {
// see https://tools.ietf.org/html/rfc8674#section-3
return $this->isSafeContentPreferred = false;
}
return $this->isSafeContentPreferred = AcceptHeader::fromString($this->headers->get('Prefer'))->has('safe');
}
/*
* The following methods are derived from code of the Zend Framework (1.10dev - 2010-01-24)
*
@@ -1856,7 +1918,7 @@ class Request
/**
* Prepares the base path.
*
* @return string base path
* @return string
*/
protected function prepareBasePath()
{
@@ -1882,7 +1944,7 @@ class Request
/**
* Prepares the path info.
*
* @return string path info
* @return string
*/
protected function preparePathInfo()
{
@@ -1898,7 +1960,7 @@ class Request
$requestUri = '/'.$requestUri;
}
if (null === ($baseUrl = $this->getBaseUrl())) {
if (null === ($baseUrl = $this->getBaseUrlReal())) {
return $requestUri;
}
@@ -1927,7 +1989,7 @@ class Request
'rdf' => ['application/rdf+xml'],
'atom' => ['application/atom+xml'],
'rss' => ['application/rss+xml'],
'form' => ['application/x-www-form-urlencoded'],
'form' => ['application/x-www-form-urlencoded', 'multipart/form-data'],
];
}
@@ -1984,7 +2046,7 @@ class Request
* This can be useful to determine whether or not to trust the
* contents of a proxy-specific header.
*
* @return bool true if the request came from a trusted proxy, false otherwise
* @return bool
*/
public function isFromTrustedProxy()
{
@@ -2002,7 +2064,7 @@ class Request
}
}
if ((self::$trustedHeaderSet & self::HEADER_FORWARDED) && $this->headers->has(self::TRUSTED_HEADERS[self::HEADER_FORWARDED])) {
if ((self::$trustedHeaderSet & self::HEADER_FORWARDED) && (isset(self::FORWARDED_PARAMS[$type])) && $this->headers->has(self::TRUSTED_HEADERS[self::HEADER_FORWARDED])) {
$forwarded = $this->headers->get(self::TRUSTED_HEADERS[self::HEADER_FORWARDED]);
$parts = HeaderUtils::split($forwarded, ',;=');
$forwardedValues = [];