Upgrade framework

This commit is contained in:
2023-11-14 16:54:35 +01:00
parent 1648a5cd42
commit 4fcf6fffcc
10548 changed files with 693138 additions and 466698 deletions

View File

@@ -18,33 +18,12 @@ namespace Symfony\Component\HttpFoundation;
*/
class AcceptHeaderItem
{
/**
* @var string
*/
private $value;
private string $value;
private float $quality = 1.0;
private int $index = 0;
private array $attributes = [];
/**
* @var float
*/
private $quality = 1.0;
/**
* @var int
*/
private $index = 0;
/**
* @var array
*/
private $attributes = array();
/**
* Constructor.
*
* @param string $value
* @param array $attributes
*/
public function __construct($value, array $attributes = array())
public function __construct(string $value, array $attributes = [])
{
$this->value = $value;
foreach ($attributes as $name => $value) {
@@ -54,45 +33,25 @@ class AcceptHeaderItem
/**
* Builds an AcceptHeaderInstance instance from a string.
*
* @param string $itemValue
*
* @return self
*/
public static function fromString($itemValue)
public static function fromString(?string $itemValue): self
{
$bits = preg_split('/\s*(?:;*("[^"]+");*|;*(\'[^\']+\');*|;+)\s*/', $itemValue, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
$value = array_shift($bits);
$attributes = array();
$parts = HeaderUtils::split($itemValue ?? '', ';=');
$lastNullAttribute = null;
foreach ($bits as $bit) {
if (($start = substr($bit, 0, 1)) === ($end = substr($bit, -1)) && ($start === '"' || $start === '\'')) {
$attributes[$lastNullAttribute] = substr($bit, 1, -1);
} elseif ('=' === $end) {
$lastNullAttribute = $bit = substr($bit, 0, -1);
$attributes[$bit] = null;
} else {
$parts = explode('=', $bit);
$attributes[$parts[0]] = isset($parts[1]) && strlen($parts[1]) > 0 ? $parts[1] : '';
}
}
$part = array_shift($parts);
$attributes = HeaderUtils::combine($parts);
return new self(($start = substr($value, 0, 1)) === ($end = substr($value, -1)) && ($start === '"' || $start === '\'') ? substr($value, 1, -1) : $value, $attributes);
return new self($part[0], $attributes);
}
/**
* Returns header value's string representation.
*
* @return string
* Returns header value's string representation.
*/
public function __toString()
public function __toString(): string
{
$string = $this->value.($this->quality < 1 ? ';q='.$this->quality : '');
if (count($this->attributes) > 0) {
$string .= ';'.implode(';', array_map(function ($name, $value) {
return sprintf(preg_match('/[,;=]/', $value) ? '%s="%s"' : '%s=%s', $name, $value);
}, array_keys($this->attributes), $this->attributes));
if (\count($this->attributes) > 0) {
$string .= '; '.HeaderUtils::toString($this->attributes, ';');
}
return $string;
@@ -101,11 +60,9 @@ class AcceptHeaderItem
/**
* Set the item value.
*
* @param string $value
*
* @return $this
*/
public function setValue($value)
public function setValue(string $value): static
{
$this->value = $value;
@@ -114,10 +71,8 @@ class AcceptHeaderItem
/**
* Returns the item value.
*
* @return string
*/
public function getValue()
public function getValue(): string
{
return $this->value;
}
@@ -125,11 +80,9 @@ class AcceptHeaderItem
/**
* Set the item quality.
*
* @param float $quality
*
* @return $this
*/
public function setQuality($quality)
public function setQuality(float $quality): static
{
$this->quality = $quality;
@@ -138,10 +91,8 @@ class AcceptHeaderItem
/**
* Returns the item quality.
*
* @return float
*/
public function getQuality()
public function getQuality(): float
{
return $this->quality;
}
@@ -149,11 +100,9 @@ class AcceptHeaderItem
/**
* Set the item index.
*
* @param int $index
*
* @return $this
*/
public function setIndex($index)
public function setIndex(int $index): static
{
$this->index = $index;
@@ -162,45 +111,32 @@ class AcceptHeaderItem
/**
* Returns the item index.
*
* @return int
*/
public function getIndex()
public function getIndex(): int
{
return $this->index;
}
/**
* Tests if an attribute exists.
*
* @param string $name
*
* @return bool
*/
public function hasAttribute($name)
public function hasAttribute(string $name): bool
{
return isset($this->attributes[$name]);
}
/**
* Returns an attribute by its name.
*
* @param string $name
* @param mixed $default
*
* @return mixed
*/
public function getAttribute($name, $default = null)
public function getAttribute(string $name, mixed $default = null): mixed
{
return isset($this->attributes[$name]) ? $this->attributes[$name] : $default;
return $this->attributes[$name] ?? $default;
}
/**
* Returns all attributes.
*
* @return array
*/
public function getAttributes()
public function getAttributes(): array
{
return $this->attributes;
}
@@ -208,17 +144,14 @@ class AcceptHeaderItem
/**
* Set an attribute.
*
* @param string $name
* @param string $value
*
* @return $this
*/
public function setAttribute($name, $value)
public function setAttribute(string $name, string $value): static
{
if ('q' === $name) {
$this->quality = (float) $value;
} else {
$this->attributes[$name] = (string) $value;
$this->attributes[$name] = $value;
}
return $this;