Update to laravel 7

This commit is contained in:
KodeStar
2022-03-10 11:54:29 +00:00
parent 61a5a1a8b0
commit f9a19fce91
7170 changed files with 274189 additions and 283773 deletions

View File

@@ -15,15 +15,20 @@ namespace Symfony\Component\HttpFoundation;
* HeaderBag is a container for HTTP headers.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @implements \IteratorAggregate<string, list<string|null>>
*/
class HeaderBag implements \IteratorAggregate, \Countable
{
protected const UPPER = '_ABCDEFGHIJKLMNOPQRSTUVWXYZ';
protected const LOWER = '-abcdefghijklmnopqrstuvwxyz';
/**
* @var array<string, list<string|null>>
*/
protected $headers = [];
protected $cacheControl = [];
/**
* @param array $headers An array of HTTP headers
*/
public function __construct(array $headers = [])
{
foreach ($headers as $key => $values) {
@@ -34,7 +39,7 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Returns the headers as a string.
*
* @return string The headers
* @return string
*/
public function __toString()
{
@@ -58,17 +63,23 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Returns the headers.
*
* @return array An array of headers
* @param string|null $key The name of the headers to return or null to get them all
*
* @return array<string, array<int, string|null>>|array<int, string|null>
*/
public function all()
public function all(string $key = null)
{
if (null !== $key) {
return $this->headers[strtr($key, self::UPPER, self::LOWER)] ?? [];
}
return $this->headers;
}
/**
* Returns the parameter keys.
*
* @return array An array of parameter keys
* @return string[]
*/
public function keys()
{
@@ -77,8 +88,6 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Replaces the current HTTP headers by a new set.
*
* @param array $headers An array of HTTP headers
*/
public function replace(array $headers = [])
{
@@ -88,8 +97,6 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Adds new headers the current HTTP headers set.
*
* @param array $headers An array of HTTP headers
*/
public function add(array $headers)
{
@@ -99,44 +106,34 @@ class HeaderBag implements \IteratorAggregate, \Countable
}
/**
* Returns a header value by name.
* Returns the first header by name or the default one.
*
* @param string $key The header name
* @param string|null $default The default value
* @param bool $first Whether to return the first value or all header values
*
* @return string|string[]|null The first header value or default value if $first is true, an array of values otherwise
* @return string|null
*/
public function get($key, $default = null, $first = true)
public function get(string $key, string $default = null)
{
$key = str_replace('_', '-', strtolower($key));
$headers = $this->all();
$headers = $this->all($key);
if (!\array_key_exists($key, $headers)) {
if (null === $default) {
return $first ? null : [];
}
return $first ? $default : [$default];
if (!$headers) {
return $default;
}
if ($first) {
return \count($headers[$key]) ? $headers[$key][0] : $default;
if (null === $headers[0]) {
return null;
}
return $headers[$key];
return (string) $headers[0];
}
/**
* Sets a header by name.
*
* @param string $key The key
* @param string|string[] $values The value or an array of values
* @param bool $replace Whether to replace the actual value or not (true by default)
* @param string|string[]|null $values The value or an array of values
* @param bool $replace Whether to replace the actual value or not (true by default)
*/
public function set($key, $values, $replace = true)
public function set(string $key, $values, bool $replace = true)
{
$key = str_replace('_', '-', strtolower($key));
$key = strtr($key, self::UPPER, self::LOWER);
if (\is_array($values)) {
$values = array_values($values);
@@ -162,36 +159,29 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Returns true if the HTTP header is defined.
*
* @param string $key The HTTP header
*
* @return bool true if the parameter exists, false otherwise
* @return bool
*/
public function has($key)
public function has(string $key)
{
return \array_key_exists(str_replace('_', '-', strtolower($key)), $this->all());
return \array_key_exists(strtr($key, self::UPPER, self::LOWER), $this->all());
}
/**
* Returns true if the given HTTP header contains the given value.
*
* @param string $key The HTTP header name
* @param string $value The HTTP value
*
* @return bool true if the value is contained in the header, false otherwise
* @return bool
*/
public function contains($key, $value)
public function contains(string $key, string $value)
{
return \in_array($value, $this->get($key, null, false));
return \in_array($value, $this->all($key));
}
/**
* Removes a header.
*
* @param string $key The HTTP header name
*/
public function remove($key)
public function remove(string $key)
{
$key = str_replace('_', '-', strtolower($key));
$key = strtr($key, self::UPPER, self::LOWER);
unset($this->headers[$key]);
@@ -203,21 +193,18 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Returns the HTTP header value converted to a date.
*
* @param string $key The parameter key
* @param \DateTime $default The default value
*
* @return \DateTime|null The parsed DateTime or the default value if the header does not exist
* @return \DateTimeInterface|null
*
* @throws \RuntimeException When the HTTP header is not parseable
*/
public function getDate($key, \DateTime $default = null)
public function getDate(string $key, \DateTime $default = null)
{
if (null === $value = $this->get($key)) {
return $default;
}
if (false === $date = \DateTime::createFromFormat(DATE_RFC2822, $value)) {
throw new \RuntimeException(sprintf('The %s HTTP header is not parseable (%s).', $key, $value));
if (false === $date = \DateTime::createFromFormat(\DATE_RFC2822, $value)) {
throw new \RuntimeException(sprintf('The "%s" HTTP header is not parseable (%s).', $key, $value));
}
return $date;
@@ -226,10 +213,9 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Adds a custom Cache-Control directive.
*
* @param string $key The Cache-Control directive name
* @param mixed $value The Cache-Control directive value
* @param bool|string $value The Cache-Control directive value
*/
public function addCacheControlDirective($key, $value = true)
public function addCacheControlDirective(string $key, $value = true)
{
$this->cacheControl[$key] = $value;
@@ -239,11 +225,9 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Returns true if the Cache-Control directive is defined.
*
* @param string $key The Cache-Control directive
*
* @return bool true if the directive exists, false otherwise
* @return bool
*/
public function hasCacheControlDirective($key)
public function hasCacheControlDirective(string $key)
{
return \array_key_exists($key, $this->cacheControl);
}
@@ -251,21 +235,17 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Returns a Cache-Control directive value by name.
*
* @param string $key The directive name
*
* @return mixed|null The directive value if defined, null otherwise
* @return bool|string|null
*/
public function getCacheControlDirective($key)
public function getCacheControlDirective(string $key)
{
return \array_key_exists($key, $this->cacheControl) ? $this->cacheControl[$key] : null;
return $this->cacheControl[$key] ?? null;
}
/**
* Removes a Cache-Control directive.
*
* @param string $key The Cache-Control directive
*/
public function removeCacheControlDirective($key)
public function removeCacheControlDirective(string $key)
{
unset($this->cacheControl[$key]);
@@ -275,8 +255,9 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Returns an iterator for headers.
*
* @return \ArrayIterator An \ArrayIterator instance
* @return \ArrayIterator<string, list<string|null>>
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
return new \ArrayIterator($this->headers);
@@ -285,8 +266,9 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Returns the number of headers.
*
* @return int The number of headers
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
{
return \count($this->headers);
@@ -302,11 +284,9 @@ class HeaderBag implements \IteratorAggregate, \Countable
/**
* Parses a Cache-Control HTTP header.
*
* @param string $header The value of the Cache-Control HTTP header
*
* @return array An array representing the attribute values
* @return array
*/
protected function parseCacheControl($header)
protected function parseCacheControl(string $header)
{
$parts = HeaderUtils::split($header, ',=');