mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 23:32:17 +02:00
N°8834 - Add compatibility with PHP 8.4 (#819)
* N°8834 - Add compatibility with PHP 8.4 * Rollback of scssphp/scssphp version upgrade due to compilation error
This commit is contained in:
@@ -177,7 +177,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
|
||||
public function getDefaultValue(): mixed
|
||||
{
|
||||
if (!$this->hasDefaultValue()) {
|
||||
throw new \RuntimeException(sprintf('The node at path "%s" has no default value.', $this->getPath()));
|
||||
throw new \RuntimeException(\sprintf('The node at path "%s" has no default value.', $this->getPath()));
|
||||
}
|
||||
|
||||
$defaults = [];
|
||||
@@ -205,7 +205,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
|
||||
throw new \InvalidArgumentException('Child nodes must be named.');
|
||||
}
|
||||
if (isset($this->children[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('A child node named "%s" already exists.', $name));
|
||||
throw new \InvalidArgumentException(\sprintf('A child node named "%s" already exists.', $name));
|
||||
}
|
||||
|
||||
$this->children[$name] = $node;
|
||||
@@ -218,15 +218,15 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
|
||||
protected function finalizeValue(mixed $value): mixed
|
||||
{
|
||||
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()) {
|
||||
$message = sprintf('The child config "%s" under "%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());
|
||||
$message .= \sprintf(': %s', $child->getInfo());
|
||||
} else {
|
||||
$message .= '.';
|
||||
}
|
||||
@@ -264,7 +264,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
|
||||
protected function validateType(mixed $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(), get_debug_type($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);
|
||||
}
|
||||
@@ -315,13 +315,13 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
|
||||
}
|
||||
}
|
||||
|
||||
$msg = sprintf('Unrecognized option%s "%s" under "%s"', 1 === \count($value) ? '' : 's', implode(', ', array_keys($value)), $this->getPath());
|
||||
$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)));
|
||||
$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));
|
||||
$msg .= \sprintf('. Available option%s %s "%s".', 1 === \count($proposals) ? '' : 's', 1 === \count($proposals) ? 'is' : 'are', implode('", "', $proposals));
|
||||
}
|
||||
|
||||
$ex = new InvalidConfigurationException($msg);
|
||||
@@ -370,7 +370,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
|
||||
// no conflict
|
||||
if (!\array_key_exists($k, $leftSide)) {
|
||||
if (!$this->allowNewKeys) {
|
||||
$ex = new InvalidConfigurationException(sprintf('You are not allowed to define new elements for path "%s". Please define all elements for this path in one config file. If you are trying to overwrite an element, make sure you redefine it with the same name.', $this->getPath()));
|
||||
$ex = new InvalidConfigurationException(\sprintf('You are not allowed to define new elements for path "%s". Please define all elements for this path in one config file. If you are trying to overwrite an element, make sure you redefine it with the same name.', $this->getPath()));
|
||||
$ex->setPath($this->getPath());
|
||||
|
||||
throw $ex;
|
||||
|
||||
@@ -46,7 +46,7 @@ abstract class BaseNode implements NodeInterface
|
||||
/**
|
||||
* @throws \InvalidArgumentException if the name contains a period
|
||||
*/
|
||||
public function __construct(?string $name, NodeInterface $parent = null, string $pathSeparator = self::DEFAULT_PATH_SEPARATOR)
|
||||
public function __construct(?string $name, ?NodeInterface $parent = null, string $pathSeparator = self::DEFAULT_PATH_SEPARATOR)
|
||||
{
|
||||
if (str_contains($name = (string) $name, $pathSeparator)) {
|
||||
throw new \InvalidArgumentException('The name must not contain ".'.$pathSeparator.'".');
|
||||
@@ -313,7 +313,7 @@ abstract class BaseNode implements NodeInterface
|
||||
final public function merge(mixed $leftSide, mixed $rightSide): mixed
|
||||
{
|
||||
if (!$this->allowOverwrite) {
|
||||
throw new ForbiddenOverwriteException(sprintf('Configuration path "%s" cannot be overwritten. You have to define all options for this path, and any of its sub-paths in one configuration section.', $this->getPath()));
|
||||
throw new ForbiddenOverwriteException(\sprintf('Configuration path "%s" cannot be overwritten. You have to define all options for this path, and any of its sub-paths in one configuration section.', $this->getPath()));
|
||||
}
|
||||
|
||||
if ($leftSide !== $leftPlaceholders = self::resolvePlaceholderValue($leftSide)) {
|
||||
@@ -432,7 +432,7 @@ abstract class BaseNode implements NodeInterface
|
||||
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
throw new InvalidConfigurationException(sprintf('Invalid configuration for path "%s": ', $this->getPath()).$e->getMessage(), $e->getCode(), $e);
|
||||
throw new InvalidConfigurationException(\sprintf('Invalid configuration for path "%s": ', $this->getPath()).$e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,7 +507,7 @@ abstract class BaseNode implements NodeInterface
|
||||
private function doValidateType(mixed $value): void
|
||||
{
|
||||
if (null !== $this->handlingPlaceholder && !$this->allowPlaceholders()) {
|
||||
$e = new InvalidTypeException(sprintf('A dynamic value is not compatible with a "%s" node type at path "%s".', static::class, $this->getPath()));
|
||||
$e = new InvalidTypeException(\sprintf('A dynamic value is not compatible with a "%s" node type at path "%s".', static::class, $this->getPath()));
|
||||
$e->setPath($this->getPath());
|
||||
|
||||
throw $e;
|
||||
@@ -523,7 +523,7 @@ abstract class BaseNode implements NodeInterface
|
||||
$validTypes = $this->getValidPlaceholderTypes();
|
||||
|
||||
if ($validTypes && array_diff($knownTypes, $validTypes)) {
|
||||
$e = new InvalidTypeException(sprintf(
|
||||
$e = new InvalidTypeException(\sprintf(
|
||||
'Invalid type for path "%s". Expected %s, but got %s.',
|
||||
$this->getPath(),
|
||||
1 === \count($validTypes) ? '"'.reset($validTypes).'"' : 'one of "'.implode('", "', $validTypes).'"',
|
||||
|
||||
@@ -26,7 +26,7 @@ class BooleanNode extends ScalarNode
|
||||
protected function validateType(mixed $value)
|
||||
{
|
||||
if (!\is_bool($value)) {
|
||||
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "bool", but got "%s".', $this->getPath(), get_debug_type($value)));
|
||||
$ex = new InvalidTypeException(\sprintf('Invalid type for path "%s". Expected "bool", but got "%s".', $this->getPath(), get_debug_type($value)));
|
||||
if ($hint = $this->getInfo()) {
|
||||
$ex->addHint($hint);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
protected $nodeBuilder;
|
||||
protected $normalizeKeys = true;
|
||||
|
||||
public function __construct(?string $name, NodeParentInterface $parent = null)
|
||||
public function __construct(?string $name, ?NodeParentInterface $parent = null)
|
||||
{
|
||||
parent::__construct($name, $parent);
|
||||
|
||||
@@ -126,7 +126,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addDefaultChildrenIfNoneSet(int|string|array $children = null): static
|
||||
public function addDefaultChildrenIfNoneSet(int|string|array|null $children = null): static
|
||||
{
|
||||
$this->addDefaultChildren = $children;
|
||||
|
||||
@@ -169,7 +169,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function fixXmlConfig(string $singular, string $plural = null): static
|
||||
public function fixXmlConfig(string $singular, ?string $plural = null): static
|
||||
{
|
||||
$this->normalization()->remap($singular, $plural);
|
||||
|
||||
@@ -331,7 +331,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
|
||||
public function append(NodeDefinition $node): static
|
||||
{
|
||||
$this->children[$node->name] = $node->setParent($this);
|
||||
$this->children[$node->name ?? ''] = $node->setParent($this);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -374,7 +374,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
|
||||
if ($this->default) {
|
||||
if (!\is_array($this->defaultValue)) {
|
||||
throw new \InvalidArgumentException(sprintf('%s: the default value of an array node has to be an array.', $node->getPath()));
|
||||
throw new \InvalidArgumentException(\sprintf('%s: the default value of an array node has to be an array.', $node->getPath()));
|
||||
}
|
||||
|
||||
$node->setDefaultValue($this->defaultValue);
|
||||
@@ -434,23 +434,23 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
$path = $node->getPath();
|
||||
|
||||
if (null !== $this->key) {
|
||||
throw new InvalidDefinitionException(sprintf('->useAttributeAsKey() is not applicable to concrete nodes at path "%s".', $path));
|
||||
throw new InvalidDefinitionException(\sprintf('->useAttributeAsKey() is not applicable to concrete nodes at path "%s".', $path));
|
||||
}
|
||||
|
||||
if (false === $this->allowEmptyValue) {
|
||||
throw new InvalidDefinitionException(sprintf('->cannotBeEmpty() is not applicable to concrete nodes at path "%s".', $path));
|
||||
throw new InvalidDefinitionException(\sprintf('->cannotBeEmpty() is not applicable to concrete nodes at path "%s".', $path));
|
||||
}
|
||||
|
||||
if (true === $this->atLeastOne) {
|
||||
throw new InvalidDefinitionException(sprintf('->requiresAtLeastOneElement() is not applicable to concrete nodes at path "%s".', $path));
|
||||
throw new InvalidDefinitionException(\sprintf('->requiresAtLeastOneElement() is not applicable to concrete nodes at path "%s".', $path));
|
||||
}
|
||||
|
||||
if ($this->default) {
|
||||
throw new InvalidDefinitionException(sprintf('->defaultValue() is not applicable to concrete nodes at path "%s".', $path));
|
||||
throw new InvalidDefinitionException(\sprintf('->defaultValue() is not applicable to concrete nodes at path "%s".', $path));
|
||||
}
|
||||
|
||||
if (false !== $this->addDefaultChildren) {
|
||||
throw new InvalidDefinitionException(sprintf('->addDefaultChildrenIfNoneSet() is not applicable to concrete nodes at path "%s".', $path));
|
||||
throw new InvalidDefinitionException(\sprintf('->addDefaultChildrenIfNoneSet() is not applicable to concrete nodes at path "%s".', $path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,20 +466,20 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
$path = $node->getPath();
|
||||
|
||||
if ($this->addDefaults) {
|
||||
throw new InvalidDefinitionException(sprintf('->addDefaultsIfNotSet() is not applicable to prototype nodes at path "%s".', $path));
|
||||
throw new InvalidDefinitionException(\sprintf('->addDefaultsIfNotSet() is not applicable to prototype nodes at path "%s".', $path));
|
||||
}
|
||||
|
||||
if (false !== $this->addDefaultChildren) {
|
||||
if ($this->default) {
|
||||
throw new InvalidDefinitionException(sprintf('A default value and default children might not be used together at path "%s".', $path));
|
||||
throw new InvalidDefinitionException(\sprintf('A default value and default children might not be used together at path "%s".', $path));
|
||||
}
|
||||
|
||||
if (null !== $this->key && (null === $this->addDefaultChildren || \is_int($this->addDefaultChildren) && $this->addDefaultChildren > 0)) {
|
||||
throw new InvalidDefinitionException(sprintf('->addDefaultChildrenIfNoneSet() should set default children names as ->useAttributeAsKey() is used at path "%s".', $path));
|
||||
throw new InvalidDefinitionException(\sprintf('->addDefaultChildrenIfNoneSet() should set default children names as ->useAttributeAsKey() is used at path "%s".', $path));
|
||||
}
|
||||
|
||||
if (null === $this->key && (\is_string($this->addDefaultChildren) || \is_array($this->addDefaultChildren))) {
|
||||
throw new InvalidDefinitionException(sprintf('->addDefaultChildrenIfNoneSet() might not set default children names as ->useAttributeAsKey() is not used at path "%s".', $path));
|
||||
throw new InvalidDefinitionException(\sprintf('->addDefaultChildrenIfNoneSet() might not set default children names as ->useAttributeAsKey() is not used at path "%s".', $path));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -504,7 +504,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
: substr($nodePath, 0, $pathSeparatorPos);
|
||||
|
||||
if (null === $node = ($this->children[$firstPathSegment] ?? null)) {
|
||||
throw new \RuntimeException(sprintf('Node with name "%s" does not exist in the current node "%s".', $firstPathSegment, $this->name));
|
||||
throw new \RuntimeException(\sprintf('Node with name "%s" does not exist in the current node "%s".', $firstPathSegment, $this->name));
|
||||
}
|
||||
|
||||
if (false === $pathSeparatorPos) {
|
||||
|
||||
@@ -21,7 +21,7 @@ use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
|
||||
*/
|
||||
class BooleanNodeDefinition extends ScalarNodeDefinition
|
||||
{
|
||||
public function __construct(?string $name, NodeParentInterface $parent = null)
|
||||
public function __construct(?string $name, ?NodeParentInterface $parent = null)
|
||||
{
|
||||
parent::__construct($name, $parent);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class ExprBuilder
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function always(\Closure $then = null): static
|
||||
public function always(?\Closure $then = null): static
|
||||
{
|
||||
$this->ifPart = static fn () => true;
|
||||
$this->allowedTypes = self::TYPE_ANY;
|
||||
@@ -61,7 +61,7 @@ class ExprBuilder
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function ifTrue(\Closure $closure = null): static
|
||||
public function ifTrue(?\Closure $closure = null): static
|
||||
{
|
||||
$this->ifPart = $closure ?? static fn ($v) => true === $v;
|
||||
$this->allowedTypes = self::TYPE_ANY;
|
||||
@@ -196,7 +196,7 @@ class ExprBuilder
|
||||
*/
|
||||
public function thenInvalid(string $message): static
|
||||
{
|
||||
$this->thenPart = static fn ($v) => throw new \InvalidArgumentException(sprintf($message, json_encode($v)));
|
||||
$this->thenPart = static fn ($v) => throw new \InvalidArgumentException(\sprintf($message, json_encode($v)));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class NodeBuilder implements NodeParentInterface
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setParent(ParentNodeDefinitionInterface $parent = null): static
|
||||
public function setParent(?ParentNodeDefinitionInterface $parent = null): static
|
||||
{
|
||||
if (1 > \func_num_args()) {
|
||||
trigger_deprecation('symfony/form', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
|
||||
@@ -190,13 +190,13 @@ class NodeBuilder implements NodeParentInterface
|
||||
$type = strtolower($type);
|
||||
|
||||
if (!isset($this->nodeMapping[$type])) {
|
||||
throw new \RuntimeException(sprintf('The node type "%s" is not registered.', $type));
|
||||
throw new \RuntimeException(\sprintf('The node type "%s" is not registered.', $type));
|
||||
}
|
||||
|
||||
$class = $this->nodeMapping[$type];
|
||||
|
||||
if (!class_exists($class)) {
|
||||
throw new \RuntimeException(sprintf('The node class "%s" does not exist.', $class));
|
||||
throw new \RuntimeException(\sprintf('The node class "%s" does not exist.', $class));
|
||||
}
|
||||
|
||||
return $class;
|
||||
|
||||
@@ -38,7 +38,7 @@ abstract class NodeDefinition implements NodeParentInterface
|
||||
protected $parent;
|
||||
protected $attributes = [];
|
||||
|
||||
public function __construct(?string $name, NodeParentInterface $parent = null)
|
||||
public function __construct(?string $name, ?NodeParentInterface $parent = null)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
$this->name = $name;
|
||||
|
||||
@@ -36,7 +36,7 @@ class NormalizationBuilder
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function remap(string $key, string $plural = null): static
|
||||
public function remap(string $key, ?string $plural = null): static
|
||||
{
|
||||
$this->remappings[] = [$key, null === $plural ? $key.'s' : $plural];
|
||||
|
||||
@@ -48,7 +48,7 @@ class NormalizationBuilder
|
||||
*
|
||||
* @return ExprBuilder|$this
|
||||
*/
|
||||
public function before(\Closure $closure = null): ExprBuilder|static
|
||||
public function before(?\Closure $closure = null): ExprBuilder|static
|
||||
{
|
||||
if (null !== $closure) {
|
||||
$this->before[] = $closure;
|
||||
|
||||
@@ -33,7 +33,7 @@ abstract class NumericNodeDefinition extends ScalarNodeDefinition
|
||||
public function max(int|float $max): static
|
||||
{
|
||||
if (isset($this->min) && $this->min > $max) {
|
||||
throw new \InvalidArgumentException(sprintf('You cannot define a max(%s) as you already have a min(%s).', $max, $this->min));
|
||||
throw new \InvalidArgumentException(\sprintf('You cannot define a max(%s) as you already have a min(%s).', $max, $this->min));
|
||||
}
|
||||
$this->max = $max;
|
||||
|
||||
@@ -50,7 +50,7 @@ abstract class NumericNodeDefinition extends ScalarNodeDefinition
|
||||
public function min(int|float $min): static
|
||||
{
|
||||
if (isset($this->max) && $this->max < $min) {
|
||||
throw new \InvalidArgumentException(sprintf('You cannot define a min(%s) as you already have a max(%s).', $min, $this->max));
|
||||
throw new \InvalidArgumentException(\sprintf('You cannot define a min(%s) as you already have a max(%s).', $min, $this->max));
|
||||
}
|
||||
$this->min = $min;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class TreeBuilder implements NodeParentInterface
|
||||
*/
|
||||
protected $root;
|
||||
|
||||
public function __construct(string $name, string $type = 'array', NodeBuilder $builder = null)
|
||||
public function __construct(string $name, string $type = 'array', ?NodeBuilder $builder = null)
|
||||
{
|
||||
$builder ??= new NodeBuilder();
|
||||
$this->root = $builder->node($name, $type)->setParent($this);
|
||||
|
||||
@@ -31,7 +31,7 @@ class ValidationBuilder
|
||||
*
|
||||
* @return ExprBuilder|$this
|
||||
*/
|
||||
public function rule(\Closure $closure = null): ExprBuilder|static
|
||||
public function rule(?\Closure $closure = null): ExprBuilder|static
|
||||
{
|
||||
if (null !== $closure) {
|
||||
$this->rules[] = $closure;
|
||||
|
||||
@@ -29,7 +29,7 @@ class DefinitionConfigurator
|
||||
) {
|
||||
}
|
||||
|
||||
public function import(string $resource, string $type = null, bool $ignoreErrors = false): void
|
||||
public function import(string $resource, ?string $type = null, bool $ignoreErrors = false): void
|
||||
{
|
||||
$this->loader->setCurrentDir(\dirname($this->path));
|
||||
$this->loader->import($resource, $type, $ignoreErrors, $this->file);
|
||||
|
||||
@@ -34,7 +34,7 @@ class XmlReferenceDumper
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function dump(ConfigurationInterface $configuration, string $namespace = null)
|
||||
public function dump(ConfigurationInterface $configuration, ?string $namespace = null)
|
||||
{
|
||||
return $this->dumpNode($configuration->getConfigTreeBuilder()->buildTree(), $namespace);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ class XmlReferenceDumper
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function dumpNode(NodeInterface $node, string $namespace = null)
|
||||
public function dumpNode(NodeInterface $node, ?string $namespace = null)
|
||||
{
|
||||
$this->reference = '';
|
||||
$this->writeNode($node, 0, true, $namespace);
|
||||
@@ -52,7 +52,7 @@ class XmlReferenceDumper
|
||||
return $ref;
|
||||
}
|
||||
|
||||
private function writeNode(NodeInterface $node, int $depth = 0, bool $root = false, string $namespace = null): void
|
||||
private function writeNode(NodeInterface $node, int $depth = 0, bool $root = false, ?string $namespace = null): void
|
||||
{
|
||||
$rootName = ($root ? 'config' : $node->getName());
|
||||
$rootNamespace = ($namespace ?: ($root ? 'http://example.org/schema/dic/'.$node->getName() : null));
|
||||
@@ -151,7 +151,7 @@ class XmlReferenceDumper
|
||||
|
||||
if ($child instanceof BaseNode && $child->isDeprecated()) {
|
||||
$deprecation = $child->getDeprecation($child->getName(), $node->getPath());
|
||||
$comments[] = sprintf('Deprecated (%s)', ($deprecation['package'] || $deprecation['version'] ? "Since {$deprecation['package']} {$deprecation['version']}: " : '').$deprecation['message']);
|
||||
$comments[] = \sprintf('Deprecated (%s)', ($deprecation['package'] || $deprecation['version'] ? "Since {$deprecation['package']} {$deprecation['version']}: " : '').$deprecation['message']);
|
||||
}
|
||||
|
||||
if ($child instanceof EnumNode) {
|
||||
@@ -205,7 +205,7 @@ class XmlReferenceDumper
|
||||
$rootOpenTag = '<'.$rootName;
|
||||
if (1 >= ($attributesCount = \count($rootAttributes))) {
|
||||
if (1 === $attributesCount) {
|
||||
$rootOpenTag .= sprintf(' %s="%s"', current(array_keys($rootAttributes)), $this->writeValue(current($rootAttributes)));
|
||||
$rootOpenTag .= \sprintf(' %s="%s"', current(array_keys($rootAttributes)), $this->writeValue(current($rootAttributes)));
|
||||
}
|
||||
|
||||
$rootOpenTag .= $rootIsEmptyTag ? ' />' : '>';
|
||||
@@ -221,7 +221,7 @@ class XmlReferenceDumper
|
||||
$i = 1;
|
||||
|
||||
foreach ($rootAttributes as $attrName => $attrValue) {
|
||||
$attr = sprintf('%s="%s"', $attrName, $this->writeValue($attrValue));
|
||||
$attr = \sprintf('%s="%s"', $attrName, $this->writeValue($attrValue));
|
||||
|
||||
$this->writeLine($attr, $depth + 4);
|
||||
|
||||
@@ -258,7 +258,7 @@ class XmlReferenceDumper
|
||||
$indent = \strlen($text) + $indent;
|
||||
$format = '%'.$indent.'s';
|
||||
|
||||
$this->reference .= sprintf($format, $text).\PHP_EOL;
|
||||
$this->reference .= \sprintf($format, $text).\PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,6 @@ use Symfony\Component\Config\Definition\EnumNode;
|
||||
use Symfony\Component\Config\Definition\NodeInterface;
|
||||
use Symfony\Component\Config\Definition\PrototypedArrayNode;
|
||||
use Symfony\Component\Config\Definition\ScalarNode;
|
||||
use Symfony\Component\Config\Definition\VariableNode;
|
||||
use Symfony\Component\Yaml\Inline;
|
||||
|
||||
/**
|
||||
@@ -47,7 +46,7 @@ class YamlReferenceDumper
|
||||
|
||||
foreach (explode('.', $path) as $step) {
|
||||
if (!$node instanceof ArrayNode) {
|
||||
throw new \UnexpectedValueException(sprintf('Unable to find node at path "%s.%s".', $rootNode->getName(), $path));
|
||||
throw new \UnexpectedValueException(\sprintf('Unable to find node at path "%s.%s".', $rootNode->getName(), $path));
|
||||
}
|
||||
|
||||
/** @var NodeInterface[] $children */
|
||||
@@ -61,7 +60,7 @@ class YamlReferenceDumper
|
||||
}
|
||||
}
|
||||
|
||||
throw new \UnexpectedValueException(sprintf('Unable to find node at path "%s.%s".', $rootNode->getName(), $path));
|
||||
throw new \UnexpectedValueException(\sprintf('Unable to find node at path "%s.%s".', $rootNode->getName(), $path));
|
||||
}
|
||||
|
||||
return $this->dumpNode($node);
|
||||
@@ -80,7 +79,7 @@ class YamlReferenceDumper
|
||||
return $ref;
|
||||
}
|
||||
|
||||
private function writeNode(NodeInterface $node, NodeInterface $parentNode = null, int $depth = 0, bool $prototypedArray = false): void
|
||||
private function writeNode(NodeInterface $node, ?NodeInterface $parentNode = null, int $depth = 0, bool $prototypedArray = false): void
|
||||
{
|
||||
$comments = [];
|
||||
$default = '';
|
||||
@@ -99,19 +98,12 @@ class YamlReferenceDumper
|
||||
$children = $this->getPrototypeChildren($node);
|
||||
}
|
||||
|
||||
if (!$children) {
|
||||
if ($node->hasDefaultValue() && \count($defaultArray = $node->getDefaultValue())) {
|
||||
$default = '';
|
||||
} elseif (!\is_array($example)) {
|
||||
$default = '[]';
|
||||
}
|
||||
if (!$children && !($node->hasDefaultValue() && \count($defaultArray = $node->getDefaultValue()))) {
|
||||
$default = '[]';
|
||||
}
|
||||
} elseif ($node instanceof EnumNode) {
|
||||
$comments[] = 'One of '.$node->getPermissibleValues('; ');
|
||||
$default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
|
||||
} elseif (VariableNode::class === $node::class && \is_array($example)) {
|
||||
// If there is an array example, we are sure we dont need to print a default value
|
||||
$default = '';
|
||||
} else {
|
||||
$default = '~';
|
||||
|
||||
@@ -138,7 +130,7 @@ class YamlReferenceDumper
|
||||
// deprecated?
|
||||
if ($node instanceof BaseNode && $node->isDeprecated()) {
|
||||
$deprecation = $node->getDeprecation($node->getName(), $parentNode ? $parentNode->getPath() : $node->getPath());
|
||||
$comments[] = sprintf('Deprecated (%s)', ($deprecation['package'] || $deprecation['version'] ? "Since {$deprecation['package']} {$deprecation['version']}: " : '').$deprecation['message']);
|
||||
$comments[] = \sprintf('Deprecated (%s)', ($deprecation['package'] || $deprecation['version'] ? "Since {$deprecation['package']} {$deprecation['version']}: " : '').$deprecation['message']);
|
||||
}
|
||||
|
||||
// example
|
||||
@@ -150,12 +142,12 @@ class YamlReferenceDumper
|
||||
$comments = \count($comments) ? '# '.implode(', ', $comments) : '';
|
||||
|
||||
$key = $prototypedArray ? '-' : $node->getName().':';
|
||||
$text = rtrim(sprintf('%-21s%s %s', $key, $default, $comments), ' ');
|
||||
$text = rtrim(\sprintf('%-21s%s %s', $key, $default, $comments), ' ');
|
||||
|
||||
if ($node instanceof BaseNode && $info = $node->getInfo()) {
|
||||
$this->writeLine('');
|
||||
// indenting multi-line info
|
||||
$info = str_replace("\n", sprintf("\n%".($depth * 4).'s# ', ' '), $info);
|
||||
$info = str_replace("\n", \sprintf("\n%".($depth * 4).'s# ', ' '), $info);
|
||||
$this->writeLine('# '.$info, $depth * 4);
|
||||
}
|
||||
|
||||
@@ -179,7 +171,7 @@ class YamlReferenceDumper
|
||||
|
||||
$this->writeLine('# '.$message.':', $depth * 4 + 4);
|
||||
|
||||
$this->writeArray(array_map(Inline::dump(...), $example), $depth + 1);
|
||||
$this->writeArray(array_map(Inline::dump(...), $example), $depth + 1, true);
|
||||
}
|
||||
|
||||
if ($children) {
|
||||
@@ -197,10 +189,10 @@ class YamlReferenceDumper
|
||||
$indent = \strlen($text) + $indent;
|
||||
$format = '%'.$indent.'s';
|
||||
|
||||
$this->reference .= sprintf($format, $text)."\n";
|
||||
$this->reference .= \sprintf($format, $text)."\n";
|
||||
}
|
||||
|
||||
private function writeArray(array $array, int $depth): void
|
||||
private function writeArray(array $array, int $depth, bool $asComment = false): void
|
||||
{
|
||||
$isIndexed = array_is_list($array);
|
||||
|
||||
@@ -211,14 +203,16 @@ class YamlReferenceDumper
|
||||
$val = $value;
|
||||
}
|
||||
|
||||
$prefix = $asComment ? '# ' : '';
|
||||
|
||||
if ($isIndexed) {
|
||||
$this->writeLine('- '.$val, $depth * 4);
|
||||
$this->writeLine($prefix.'- '.$val, $depth * 4);
|
||||
} else {
|
||||
$this->writeLine(sprintf('%-20s %s', $key.':', $val), $depth * 4);
|
||||
$this->writeLine(\sprintf('%s%-20s %s', $prefix, $key.':', $val), $depth * 4);
|
||||
}
|
||||
|
||||
if (\is_array($value)) {
|
||||
$this->writeArray($value, $depth + 1);
|
||||
$this->writeArray($value, $depth + 1, $asComment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,6 +249,6 @@ class YamlReferenceDumper
|
||||
}
|
||||
$keyNode->setInfo($info);
|
||||
|
||||
return [$key => $keyNode];
|
||||
return [$key ?? '' => $keyNode];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class EnumNode extends ScalarNode
|
||||
{
|
||||
private array $values;
|
||||
|
||||
public function __construct(?string $name, NodeInterface $parent = null, array $values = [], string $pathSeparator = BaseNode::DEFAULT_PATH_SEPARATOR)
|
||||
public function __construct(?string $name, ?NodeInterface $parent = null, array $values = [], string $pathSeparator = BaseNode::DEFAULT_PATH_SEPARATOR)
|
||||
{
|
||||
if (!$values) {
|
||||
throw new \InvalidArgumentException('$values must contain at least one element.');
|
||||
@@ -34,11 +34,11 @@ class EnumNode extends ScalarNode
|
||||
}
|
||||
|
||||
if (!$value instanceof \UnitEnum) {
|
||||
throw new \InvalidArgumentException(sprintf('"%s" only supports scalar, enum, or null values, "%s" given.', __CLASS__, get_debug_type($value)));
|
||||
throw new \InvalidArgumentException(\sprintf('"%s" only supports scalar, enum, or null values, "%s" given.', __CLASS__, get_debug_type($value)));
|
||||
}
|
||||
|
||||
if ($value::class !== ($enumClass ??= $value::class)) {
|
||||
throw new \InvalidArgumentException(sprintf('"%s" only supports one type of enum, "%s" and "%s" passed.', __CLASS__, $enumClass, $value::class));
|
||||
throw new \InvalidArgumentException(\sprintf('"%s" only supports one type of enum, "%s" and "%s" passed.', __CLASS__, $enumClass, $value::class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class EnumNode extends ScalarNode
|
||||
$value = parent::finalizeValue($value);
|
||||
|
||||
if (!\in_array($value, $this->values, true)) {
|
||||
$ex = new InvalidConfigurationException(sprintf('The value %s is not allowed for path "%s". Permissible values: %s', json_encode($value), $this->getPath(), $this->getPermissibleValues(', ')));
|
||||
$ex = new InvalidConfigurationException(\sprintf('The value %s is not allowed for path "%s". Permissible values: %s', json_encode($value), $this->getPath(), $this->getPermissibleValues(', ')));
|
||||
$ex->setPath($this->getPath());
|
||||
|
||||
throw $ex;
|
||||
|
||||
@@ -31,7 +31,7 @@ class FloatNode extends NumericNode
|
||||
}
|
||||
|
||||
if (!\is_float($value)) {
|
||||
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "float", but got "%s".', $this->getPath(), get_debug_type($value)));
|
||||
$ex = new InvalidTypeException(\sprintf('Invalid type for path "%s". Expected "float", but got "%s".', $this->getPath(), get_debug_type($value)));
|
||||
if ($hint = $this->getInfo()) {
|
||||
$ex->addHint($hint);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class IntegerNode extends NumericNode
|
||||
protected function validateType(mixed $value)
|
||||
{
|
||||
if (!\is_int($value)) {
|
||||
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "int", but got "%s".', $this->getPath(), get_debug_type($value)));
|
||||
$ex = new InvalidTypeException(\sprintf('Invalid type for path "%s". Expected "int", but got "%s".', $this->getPath(), get_debug_type($value)));
|
||||
if ($hint = $this->getInfo()) {
|
||||
$ex->addHint($hint);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class DefinitionFileLoader extends FileLoader
|
||||
parent::__construct($locator);
|
||||
}
|
||||
|
||||
public function load(mixed $resource, string $type = null): mixed
|
||||
public function load(mixed $resource, ?string $type = null): mixed
|
||||
{
|
||||
// the loader variable is exposed to the included file below
|
||||
$loader = $this;
|
||||
@@ -57,7 +57,7 @@ class DefinitionFileLoader extends FileLoader
|
||||
return null;
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
if (!\is_string($resource)) {
|
||||
return false;
|
||||
@@ -81,7 +81,7 @@ class DefinitionFileLoader extends FileLoader
|
||||
$reflectionType = $parameter->getType();
|
||||
|
||||
if (!$reflectionType instanceof \ReflectionNamedType) {
|
||||
throw new \InvalidArgumentException(sprintf('Could not resolve argument "$%s" for "%s". You must typehint it (for example with "%s").', $parameter->getName(), $path, DefinitionConfigurator::class));
|
||||
throw new \InvalidArgumentException(\sprintf('Could not resolve argument "$%s" for "%s". You must typehint it (for example with "%s").', $parameter->getName(), $path, DefinitionConfigurator::class));
|
||||
}
|
||||
|
||||
$arguments[] = match ($reflectionType->getName()) {
|
||||
|
||||
@@ -23,7 +23,7 @@ class NumericNode extends ScalarNode
|
||||
protected $min;
|
||||
protected $max;
|
||||
|
||||
public function __construct(?string $name, NodeInterface $parent = null, int|float $min = null, int|float $max = null, string $pathSeparator = BaseNode::DEFAULT_PATH_SEPARATOR)
|
||||
public function __construct(?string $name, ?NodeInterface $parent = null, int|float|null $min = null, int|float|null $max = null, string $pathSeparator = BaseNode::DEFAULT_PATH_SEPARATOR)
|
||||
{
|
||||
parent::__construct($name, $parent, $pathSeparator);
|
||||
$this->min = $min;
|
||||
@@ -36,10 +36,10 @@ class NumericNode extends ScalarNode
|
||||
|
||||
$errorMsg = null;
|
||||
if (isset($this->min) && $value < $this->min) {
|
||||
$errorMsg = sprintf('The value %s is too small for path "%s". Should be greater than or equal to %s', $value, $this->getPath(), $this->min);
|
||||
$errorMsg = \sprintf('The value %s is too small for path "%s". Should be greater than or equal to %s', $value, $this->getPath(), $this->min);
|
||||
}
|
||||
if (isset($this->max) && $value > $this->max) {
|
||||
$errorMsg = sprintf('The value %s is too big for path "%s". Should be less than or equal to %s', $value, $this->getPath(), $this->max);
|
||||
$errorMsg = \sprintf('The value %s is too big for path "%s". Should be less than or equal to %s', $value, $this->getPath(), $this->max);
|
||||
}
|
||||
if (isset($errorMsg)) {
|
||||
$ex = new InvalidConfigurationException($errorMsg);
|
||||
|
||||
@@ -67,7 +67,7 @@ class Processor
|
||||
* @param string $key The key to normalize
|
||||
* @param string|null $plural The plural form of the key if it is irregular
|
||||
*/
|
||||
public static function normalizeConfig(array $config, string $key, string $plural = null): array
|
||||
public static function normalizeConfig(array $config, string $key, ?string $plural = null): array
|
||||
{
|
||||
$plural ??= $key.'s';
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ class PrototypedArrayNode extends ArrayNode
|
||||
protected function finalizeValue(mixed $value): mixed
|
||||
{
|
||||
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 ($value as $k => $v) {
|
||||
@@ -181,7 +181,7 @@ class PrototypedArrayNode extends ArrayNode
|
||||
}
|
||||
|
||||
if (\count($value) < $this->minNumberOfElements) {
|
||||
$ex = new InvalidConfigurationException(sprintf('The path "%s" should have at least %d element(s) defined.', $this->getPath(), $this->minNumberOfElements));
|
||||
$ex = new InvalidConfigurationException(\sprintf('The path "%s" should have at least %d element(s) defined.', $this->getPath(), $this->minNumberOfElements));
|
||||
$ex->setPath($this->getPath());
|
||||
|
||||
throw $ex;
|
||||
@@ -206,7 +206,7 @@ class PrototypedArrayNode extends ArrayNode
|
||||
foreach ($value as $k => $v) {
|
||||
if (null !== $this->keyAttribute && \is_array($v)) {
|
||||
if (!isset($v[$this->keyAttribute]) && \is_int($k) && $isList) {
|
||||
$ex = new InvalidConfigurationException(sprintf('The attribute "%s" must be set for path "%s".', $this->keyAttribute, $this->getPath()));
|
||||
$ex = new InvalidConfigurationException(\sprintf('The attribute "%s" must be set for path "%s".', $this->keyAttribute, $this->getPath()));
|
||||
$ex->setPath($this->getPath());
|
||||
|
||||
throw $ex;
|
||||
@@ -239,7 +239,7 @@ class PrototypedArrayNode extends ArrayNode
|
||||
}
|
||||
|
||||
if (\array_key_exists($k, $normalized)) {
|
||||
$ex = new DuplicateKeyException(sprintf('Duplicate key "%s" for path "%s".', $k, $this->getPath()));
|
||||
$ex = new DuplicateKeyException(\sprintf('Duplicate key "%s" for path "%s".', $k, $this->getPath()));
|
||||
$ex->setPath($this->getPath());
|
||||
|
||||
throw $ex;
|
||||
@@ -280,7 +280,7 @@ class PrototypedArrayNode extends ArrayNode
|
||||
// no conflict
|
||||
if (!\array_key_exists($k, $leftSide)) {
|
||||
if (!$this->allowNewKeys) {
|
||||
$ex = new InvalidConfigurationException(sprintf('You are not allowed to define new elements for path "%s". Please define all elements for this path in one config file.', $this->getPath()));
|
||||
$ex = new InvalidConfigurationException(\sprintf('You are not allowed to define new elements for path "%s". Please define all elements for this path in one config file.', $this->getPath()));
|
||||
$ex->setPath($this->getPath());
|
||||
|
||||
throw $ex;
|
||||
|
||||
@@ -33,7 +33,7 @@ class ScalarNode extends VariableNode
|
||||
protected function validateType(mixed $value)
|
||||
{
|
||||
if (!\is_scalar($value) && null !== $value) {
|
||||
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected "scalar", but got "%s".', $this->getPath(), get_debug_type($value)));
|
||||
$ex = new InvalidTypeException(\sprintf('Invalid type for path "%s". Expected "scalar", but got "%s".', $this->getPath(), get_debug_type($value)));
|
||||
if ($hint = $this->getInfo()) {
|
||||
$ex->addHint($hint);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ class VariableNode extends BaseNode implements PrototypeNodeInterface
|
||||
// deny environment variables only when using custom validators
|
||||
// this avoids ever passing an empty value to final validation closures
|
||||
if (!$this->allowEmptyValue && $this->isHandlingPlaceholder() && $this->finalValidationClosures) {
|
||||
$e = new InvalidConfigurationException(sprintf('The path "%s" cannot contain an environment variable when empty values are not allowed by definition and are validated.', $this->getPath()));
|
||||
$e = new InvalidConfigurationException(\sprintf('The path "%s" cannot contain an environment variable when empty values are not allowed by definition and are validated.', $this->getPath()));
|
||||
if ($hint = $this->getInfo()) {
|
||||
$e->addHint($hint);
|
||||
}
|
||||
@@ -90,7 +90,7 @@ class VariableNode extends BaseNode implements PrototypeNodeInterface
|
||||
}
|
||||
|
||||
if (!$this->allowEmptyValue && $this->isValueEmpty($value)) {
|
||||
$ex = new InvalidConfigurationException(sprintf('The path "%s" cannot contain an empty value, but got %s.', $this->getPath(), json_encode($value)));
|
||||
$ex = new InvalidConfigurationException(\sprintf('The path "%s" cannot contain an empty value, but got %s.', $this->getPath(), json_encode($value)));
|
||||
if ($hint = $this->getInfo()) {
|
||||
$ex->addHint($hint);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user