migration symfony 5 4 (#300)

* symfony 5.4 (diff dev)

* symfony 5.4 (working)

* symfony 5.4 (update autoload)

* symfony 5.4 (remove swiftmailer mailer implementation)

* symfony 5.4 (php doc and split Global accessor class)


### Impacted packages:

composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies

composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
bdalsass
2022-06-16 09:13:24 +02:00
committed by GitHub
parent abb13b70b9
commit 79da71ecf8
2178 changed files with 87439 additions and 59451 deletions

View File

@@ -32,9 +32,9 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
protected $removeExtraKeys = true;
protected $normalizeKeys = true;
public function setNormalizeKeys($normalizeKeys)
public function setNormalizeKeys(bool $normalizeKeys)
{
$this->normalizeKeys = (bool) $normalizeKeys;
$this->normalizeKeys = $normalizeKeys;
}
/**
@@ -55,7 +55,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
$normalized = [];
foreach ($value as $k => $v) {
if (false !== strpos($k, '-') && false === strpos($k, '_') && !\array_key_exists($normalizedKey = str_replace('-', '_', $k), $value)) {
if (str_contains($k, '-') && !str_contains($k, '_') && !\array_key_exists($normalizedKey = str_replace('-', '_', $k), $value)) {
$normalized[$normalizedKey] = $v;
} else {
$normalized[$k] = $v;
@@ -68,7 +68,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
/**
* Retrieves the children of this node.
*
* @return array The children
* @return array<string, NodeInterface>
*/
public function getChildren()
{
@@ -98,42 +98,34 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
/**
* Sets whether to add default values for this array if it has not been
* defined in any of the configuration files.
*
* @param bool $boolean
*/
public function setAddIfNotSet($boolean)
public function setAddIfNotSet(bool $boolean)
{
$this->addIfNotSet = (bool) $boolean;
$this->addIfNotSet = $boolean;
}
/**
* Sets whether false is allowed as value indicating that the array should be unset.
*
* @param bool $allow
*/
public function setAllowFalse($allow)
public function setAllowFalse(bool $allow)
{
$this->allowFalse = (bool) $allow;
$this->allowFalse = $allow;
}
/**
* Sets whether new keys can be defined in subsequent configurations.
*
* @param bool $allow
*/
public function setAllowNewKeys($allow)
public function setAllowNewKeys(bool $allow)
{
$this->allowNewKeys = (bool) $allow;
$this->allowNewKeys = $allow;
}
/**
* Sets if deep merging should occur.
*
* @param bool $boolean
*/
public function setPerformDeepMerging($boolean)
public function setPerformDeepMerging(bool $boolean)
{
$this->performDeepMerging = (bool) $boolean;
$this->performDeepMerging = $boolean;
}
/**
@@ -142,16 +134,24 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
* @param bool $boolean To allow extra keys
* @param bool $remove To remove extra keys
*/
public function setIgnoreExtraKeys($boolean, $remove = true)
public function setIgnoreExtraKeys(bool $boolean, bool $remove = true)
{
$this->ignoreExtraKeys = (bool) $boolean;
$this->ignoreExtraKeys = $boolean;
$this->removeExtraKeys = $this->ignoreExtraKeys && $remove;
}
/**
* Returns true when extra keys should be ignored without an exception.
*/
public function shouldIgnoreExtraKeys(): bool
{
return $this->ignoreExtraKeys;
}
/**
* {@inheritdoc}
*/
public function setName($name)
public function setName(string $name)
{
$this->name = $name;
}
@@ -192,7 +192,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
public function addChild(NodeInterface $node)
{
$name = $node->getName();
if (!\strlen($name)) {
if ('' === $name) {
throw new \InvalidArgumentException('Child nodes must be named.');
}
if (isset($this->children[$name])) {
@@ -203,11 +203,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
}
/**
* Finalizes the value of this node.
*
* @param mixed $value
*
* @return mixed The finalised value
* {@inheritdoc}
*
* @throws UnsetKeyException
* @throws InvalidConfigurationException if the node doesn't have enough children
@@ -215,13 +211,19 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
protected function finalizeValue($value)
{
if (false === $value) {
throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: "%s".', $this->getPath(), json_encode($value)));
throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: %s.', $this->getPath(), json_encode($value)));
}
foreach ($this->children as $name => $child) {
if (!\array_key_exists($name, $value)) {
if ($child->isRequired()) {
$ex = new InvalidConfigurationException(sprintf('The child node "%s" at path "%s" must be configured.', $name, $this->getPath()));
$message = sprintf('The child config "%s" under "%s" must be configured', $name, $this->getPath());
if ($child->getInfo()) {
$message .= sprintf(': %s', $child->getInfo());
} else {
$message .= '.';
}
$ex = new InvalidConfigurationException($message);
$ex->setPath($this->getPath());
throw $ex;
@@ -235,7 +237,8 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
}
if ($child->isDeprecated()) {
@trigger_error($child->getDeprecationMessage($name, $this->getPath()), \E_USER_DEPRECATED);
$deprecation = $child->getDeprecation($name, $this->getPath());
trigger_deprecation($deprecation['package'], $deprecation['version'], $deprecation['message']);
}
try {
@@ -249,16 +252,12 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
}
/**
* Validates the type of the value.
*
* @param mixed $value
*
* @throws InvalidTypeException
* {@inheritdoc}
*/
protected function validateType($value)
{
if (!\is_array($value) && (!$this->allowFalse || false !== $value)) {
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected array, but got %s', $this->getPath(), \gettype($value)));
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "array", but got "%s"', $this->getPath(), get_debug_type($value)));
if ($hint = $this->getInfo()) {
$ex->addHint($hint);
}
@@ -269,11 +268,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
}
/**
* Normalizes the value.
*
* @param mixed $value The value to normalize
*
* @return mixed The normalized value
* {@inheritdoc}
*
* @throws InvalidConfigurationException
*/
@@ -300,7 +295,31 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
// if extra fields are present, throw exception
if (\count($value) && !$this->ignoreExtraKeys) {
$ex = new InvalidConfigurationException(sprintf('Unrecognized option%s "%s" under "%s"', 1 === \count($value) ? '' : 's', implode(', ', array_keys($value)), $this->getPath()));
$proposals = array_keys($this->children);
sort($proposals);
$guesses = [];
foreach (array_keys($value) as $subject) {
$minScore = \INF;
foreach ($proposals as $proposal) {
$distance = levenshtein($subject, $proposal);
if ($distance <= $minScore && $distance < 3) {
$guesses[$proposal] = $distance;
$minScore = $distance;
}
}
}
$msg = sprintf('Unrecognized option%s "%s" under "%s"', 1 === \count($value) ? '' : 's', implode(', ', array_keys($value)), $this->getPath());
if (\count($guesses)) {
asort($guesses);
$msg .= sprintf('. Did you mean "%s"?', implode('", "', array_keys($guesses)));
} else {
$msg .= sprintf('. Available option%s %s "%s".', 1 === \count($proposals) ? '' : 's', 1 === \count($proposals) ? 'is' : 'are', implode('", "', $proposals));
}
$ex = new InvalidConfigurationException($msg);
$ex->setPath($this->getPath());
throw $ex;
@@ -312,13 +331,11 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
/**
* Remaps multiple singular values to a single plural value.
*
* @param array $value The source values
*
* @return array The remapped values
* @return array
*/
protected function remapXml($value)
protected function remapXml(array $value)
{
foreach ($this->xmlRemappings as list($singular, $plural)) {
foreach ($this->xmlRemappings as [$singular, $plural]) {
if (!isset($value[$singular])) {
continue;
}
@@ -331,12 +348,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
}
/**
* Merges values together.
*
* @param mixed $leftSide The left side to merge
* @param mixed $rightSide The right side to merge
*
* @return mixed The merged values
* {@inheritdoc}
*
* @throws InvalidConfigurationException
* @throws \RuntimeException
@@ -368,7 +380,12 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
}
if (!isset($this->children[$k])) {
throw new \RuntimeException('merge() expects a normalized config array.');
if (!$this->ignoreExtraKeys || $this->removeExtraKeys) {
throw new \RuntimeException('merge() expects a normalized config array.');
}
$leftSide[$k] = $v;
continue;
}
$leftSide[$k] = $this->children[$k]->merge($leftSide[$k], $v);
@@ -376,4 +393,12 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
return $leftSide;
}
/**
* {@inheritdoc}
*/
protected function allowPlaceholders(): bool
{
return false;
}
}