From 1264225f4ebc535deec491737b70d9bc1d84dc98 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Sat, 19 Mar 2022 01:08:53 +0100 Subject: [PATCH] [Config] Fix using null values with config builders --- .../Component/Config/Builder/ClassBuilder.php | 7 ++- .../Config/Builder/ConfigBuilderGenerator.php | 30 +++++++--- .../AddToList/Messenger/ReceivingConfig.php | 15 +++-- .../AddToList/Messenger/RoutingConfig.php | 9 ++- .../Config/AddToList/MessengerConfig.php | 17 ++++-- .../Config/AddToList/TranslatorConfig.php | 15 +++-- .../Symfony/Config/AddToListConfig.php | 15 +++-- .../Fixtures/ArrayExtraKeys.output.php | 1 + .../Config/ArrayExtraKeys/BarConfig.php | 21 +++---- .../Config/ArrayExtraKeys/BazConfig.php | 8 +-- .../Config/ArrayExtraKeys/FooConfig.php | 21 +++---- .../Symfony/Config/ArrayExtraKeysConfig.php | 22 +++++--- .../Fixtures/NodeInitialValues.config.php | 2 +- .../Fixtures/NodeInitialValues.output.php | 1 + .../Builder/Fixtures/NodeInitialValues.php | 1 + .../Messenger/TransportsConfig.php | 21 ++++--- .../NodeInitialValues/MessengerConfig.php | 10 +++- .../SomeCleverNameConfig.php | 38 +++++++++++-- .../Config/NodeInitialValuesConfig.php | 15 +++-- .../Symfony/Config/PlaceholdersConfig.php | 21 ++++--- .../Fixtures/PrimitiveTypes.config.php | 1 + .../Fixtures/PrimitiveTypes.output.php | 1 + .../Tests/Builder/Fixtures/PrimitiveTypes.php | 1 + .../Symfony/Config/PrimitiveTypesConfig.php | 56 +++++++++++++++---- .../Symfony/Config/VariableTypeConfig.php | 9 ++- .../Tests/Builder/GeneratedConfigTest.php | 5 ++ 26 files changed, 253 insertions(+), 110 deletions(-) diff --git a/src/Symfony/Component/Config/Builder/ClassBuilder.php b/src/Symfony/Component/Config/Builder/ClassBuilder.php index 26fcab400172e..82fadf691f69d 100644 --- a/src/Symfony/Component/Config/Builder/ClassBuilder.php +++ b/src/Symfony/Component/Config/Builder/ClassBuilder.php @@ -93,7 +93,7 @@ public function build(): string USE /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class CLASS IMPLEMENTS { @@ -124,14 +124,15 @@ public function addMethod(string $name, string $body, array $params = []): void $this->methods[] = new Method(strtr($body, ['NAME' => $this->camelCase($name)] + $params)); } - public function addProperty(string $name, string $classType = null): Property + public function addProperty(string $name, string $classType = null, string $defaultValue = null): Property { $property = new Property($name, '_' !== $name[0] ? $this->camelCase($name) : $name); if (null !== $classType) { $property->setType($classType); } $this->properties[] = $property; - $property->setContent(sprintf('private $%s;', $property->getName())); + $defaultValue = null !== $defaultValue ? sprintf(' = %s', $defaultValue) : ''; + $property->setContent(sprintf('private $%s%s;', $property->getName(), $defaultValue)); return $property; } diff --git a/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php b/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php index 979c95522704c..920f12104f3a6 100644 --- a/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php +++ b/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php @@ -31,6 +31,9 @@ */ class ConfigBuilderGenerator implements ConfigBuilderGeneratorInterface { + /** + * @var ClassBuilder[] + */ private $classes; private $outputDir; @@ -89,6 +92,9 @@ private function writeClasses(): void foreach ($this->classes as $class) { $this->buildConstructor($class); $this->buildToArray($class); + if ($class->getProperties()) { + $class->addProperty('_usedProperties', null, '[]'); + } $this->buildSetExtraKey($class); file_put_contents($this->getFullPath($class), $class->build()); @@ -135,6 +141,7 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n public function NAME(array $value = []): CLASS { if (null === $this->PROPERTY) { + $this->_usedProperties[\'PROPERTY\'] = true; $this->PROPERTY = new CLASS($value); } elseif ([] !== $value) { throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\'); @@ -160,6 +167,7 @@ private function handleVariableNode(VariableNode $node, ClassBuilder $class): vo */ public function NAME($valueDEFAULT): self { + $this->_usedProperties[\'PROPERTY\'] = true; $this->PROPERTY = $value; return $this; @@ -186,6 +194,7 @@ private function handlePrototypedArrayNode(PrototypedArrayNode $node, ClassBuild */ public function NAME($value): self { + $this->_usedProperties[\'PROPERTY\'] = true; $this->PROPERTY = $value; return $this; @@ -200,6 +209,7 @@ public function NAME($value): self */ public function NAME(string $VAR, $VALUE): self { + $this->_usedProperties[\'PROPERTY\'] = true; $this->PROPERTY[$VAR] = $VALUE; return $this; @@ -223,6 +233,8 @@ public function NAME(string $VAR, $VALUE): self $body = ' public function NAME(array $value = []): CLASS { + $this->_usedProperties[\'PROPERTY\'] = true; + return $this->PROPERTY[] = new CLASS($value); }'; $class->addMethod($methodName, $body, ['PROPERTY' => $property->getName(), 'CLASS' => $childClass->getFqcn()]); @@ -231,9 +243,11 @@ public function NAME(array $value = []): CLASS public function NAME(string $VAR, array $VALUE = []): CLASS { if (!isset($this->PROPERTY[$VAR])) { - return $this->PROPERTY[$VAR] = new CLASS($value); + $this->_usedProperties[\'PROPERTY\'] = true; + + return $this->PROPERTY[$VAR] = new CLASS($VALUE); } - if ([] === $value) { + if ([] === $VALUE) { return $this->PROPERTY[$VAR]; } @@ -258,6 +272,7 @@ private function handleScalarNode(ScalarNode $node, ClassBuilder $class): void */ public function NAME($value): self { + $this->_usedProperties[\'PROPERTY\'] = true; $this->PROPERTY = $value; return $this; @@ -367,7 +382,7 @@ private function buildToArray(ClassBuilder $class): void } $body .= strtr(' - if (null !== $this->PROPERTY) { + if (isset($this->_usedProperties[\'PROPERTY\'])) { $output[\'ORG_NAME\'] = '.$code.'; }', ['PROPERTY' => $p->getName(), 'ORG_NAME' => $p->getOriginalName()]); } @@ -397,7 +412,8 @@ private function buildConstructor(ClassBuilder $class): void } $body .= strtr(' - if (isset($value[\'ORG_NAME\'])) { + if (array_key_exists(\'ORG_NAME\', $value)) { + $this->_usedProperties[\'PROPERTY\'] = true; $this->PROPERTY = '.$code.'; unset($value[\'ORG_NAME\']); } @@ -441,11 +457,7 @@ private function buildSetExtraKey(ClassBuilder $class): void */ public function NAME(string $key, $value): self { - if (null === $value) { - unset($this->_extraKeys[$key]); - } else { - $this->_extraKeys[$key] = $value; - } + $this->_extraKeys[$key] = $value; return $this; }'); diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/ReceivingConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/ReceivingConfig.php index ca4db117acd37..c757266195482 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/ReceivingConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/ReceivingConfig.php @@ -8,12 +8,13 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class ReceivingConfig { private $priority; private $color; + private $_usedProperties = []; /** * @default null @@ -22,6 +23,7 @@ class ReceivingConfig */ public function priority($value): self { + $this->_usedProperties['priority'] = true; $this->priority = $value; return $this; @@ -34,6 +36,7 @@ public function priority($value): self */ public function color($value): self { + $this->_usedProperties['color'] = true; $this->color = $value; return $this; @@ -42,12 +45,14 @@ public function color($value): self public function __construct(array $value = []) { - if (isset($value['priority'])) { + if (array_key_exists('priority', $value)) { + $this->_usedProperties['priority'] = true; $this->priority = $value['priority']; unset($value['priority']); } - if (isset($value['color'])) { + if (array_key_exists('color', $value)) { + $this->_usedProperties['color'] = true; $this->color = $value['color']; unset($value['color']); } @@ -60,10 +65,10 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->priority) { + if (isset($this->_usedProperties['priority'])) { $output['priority'] = $this->priority; } - if (null !== $this->color) { + if (isset($this->_usedProperties['color'])) { $output['color'] = $this->color; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/RoutingConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/RoutingConfig.php index 7f44a8553f66f..275dca34da3af 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/RoutingConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/Messenger/RoutingConfig.php @@ -8,11 +8,12 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class RoutingConfig { private $senders; + private $_usedProperties = []; /** * @param ParamConfigurator|list $value @@ -20,6 +21,7 @@ class RoutingConfig */ public function senders($value): self { + $this->_usedProperties['senders'] = true; $this->senders = $value; return $this; @@ -28,7 +30,8 @@ public function senders($value): self public function __construct(array $value = []) { - if (isset($value['senders'])) { + if (array_key_exists('senders', $value)) { + $this->_usedProperties['senders'] = true; $this->senders = $value['senders']; unset($value['senders']); } @@ -41,7 +44,7 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->senders) { + if (isset($this->_usedProperties['senders'])) { $output['senders'] = $this->senders; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/MessengerConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/MessengerConfig.php index 2189fde0f3bec..85b593a1b05f1 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/MessengerConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/MessengerConfig.php @@ -9,16 +9,19 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class MessengerConfig { private $routing; private $receiving; + private $_usedProperties = []; public function routing(string $message_class, array $value = []): \Symfony\Config\AddToList\Messenger\RoutingConfig { if (!isset($this->routing[$message_class])) { + $this->_usedProperties['routing'] = true; + return $this->routing[$message_class] = new \Symfony\Config\AddToList\Messenger\RoutingConfig($value); } if ([] === $value) { @@ -30,18 +33,22 @@ public function routing(string $message_class, array $value = []): \Symfony\Conf public function receiving(array $value = []): \Symfony\Config\AddToList\Messenger\ReceivingConfig { + $this->_usedProperties['receiving'] = true; + return $this->receiving[] = new \Symfony\Config\AddToList\Messenger\ReceivingConfig($value); } public function __construct(array $value = []) { - if (isset($value['routing'])) { + if (array_key_exists('routing', $value)) { + $this->_usedProperties['routing'] = true; $this->routing = array_map(function ($v) { return new \Symfony\Config\AddToList\Messenger\RoutingConfig($v); }, $value['routing']); unset($value['routing']); } - if (isset($value['receiving'])) { + if (array_key_exists('receiving', $value)) { + $this->_usedProperties['receiving'] = true; $this->receiving = array_map(function ($v) { return new \Symfony\Config\AddToList\Messenger\ReceivingConfig($v); }, $value['receiving']); unset($value['receiving']); } @@ -54,10 +61,10 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->routing) { + if (isset($this->_usedProperties['routing'])) { $output['routing'] = array_map(function ($v) { return $v->toArray(); }, $this->routing); } - if (null !== $this->receiving) { + if (isset($this->_usedProperties['receiving'])) { $output['receiving'] = array_map(function ($v) { return $v->toArray(); }, $this->receiving); } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/TranslatorConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/TranslatorConfig.php index 570e415ce2830..79f041cea6da0 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/TranslatorConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToList/TranslatorConfig.php @@ -8,12 +8,13 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class TranslatorConfig { private $fallbacks; private $sources; + private $_usedProperties = []; /** * @param ParamConfigurator|list $value @@ -21,6 +22,7 @@ class TranslatorConfig */ public function fallbacks($value): self { + $this->_usedProperties['fallbacks'] = true; $this->fallbacks = $value; return $this; @@ -32,6 +34,7 @@ public function fallbacks($value): self */ public function source(string $source_class, $value): self { + $this->_usedProperties['sources'] = true; $this->sources[$source_class] = $value; return $this; @@ -40,12 +43,14 @@ public function source(string $source_class, $value): self public function __construct(array $value = []) { - if (isset($value['fallbacks'])) { + if (array_key_exists('fallbacks', $value)) { + $this->_usedProperties['fallbacks'] = true; $this->fallbacks = $value['fallbacks']; unset($value['fallbacks']); } - if (isset($value['sources'])) { + if (array_key_exists('sources', $value)) { + $this->_usedProperties['sources'] = true; $this->sources = $value['sources']; unset($value['sources']); } @@ -58,10 +63,10 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->fallbacks) { + if (isset($this->_usedProperties['fallbacks'])) { $output['fallbacks'] = $this->fallbacks; } - if (null !== $this->sources) { + if (isset($this->_usedProperties['sources'])) { $output['sources'] = $this->sources; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToListConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToListConfig.php index 679aa9bbc7fca..e6f0c262b88db 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToListConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList/Symfony/Config/AddToListConfig.php @@ -9,16 +9,18 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class AddToListConfig implements \Symfony\Component\Config\Builder\ConfigBuilderInterface { private $translator; private $messenger; + private $_usedProperties = []; public function translator(array $value = []): \Symfony\Config\AddToList\TranslatorConfig { if (null === $this->translator) { + $this->_usedProperties['translator'] = true; $this->translator = new \Symfony\Config\AddToList\TranslatorConfig($value); } elseif ([] !== $value) { throw new InvalidConfigurationException('The node created by "translator()" has already been initialized. You cannot pass values the second time you call translator().'); @@ -30,6 +32,7 @@ public function translator(array $value = []): \Symfony\Config\AddToList\Transla public function messenger(array $value = []): \Symfony\Config\AddToList\MessengerConfig { if (null === $this->messenger) { + $this->_usedProperties['messenger'] = true; $this->messenger = new \Symfony\Config\AddToList\MessengerConfig($value); } elseif ([] !== $value) { throw new InvalidConfigurationException('The node created by "messenger()" has already been initialized. You cannot pass values the second time you call messenger().'); @@ -46,12 +49,14 @@ public function getExtensionAlias(): string public function __construct(array $value = []) { - if (isset($value['translator'])) { + if (array_key_exists('translator', $value)) { + $this->_usedProperties['translator'] = true; $this->translator = new \Symfony\Config\AddToList\TranslatorConfig($value['translator']); unset($value['translator']); } - if (isset($value['messenger'])) { + if (array_key_exists('messenger', $value)) { + $this->_usedProperties['messenger'] = true; $this->messenger = new \Symfony\Config\AddToList\MessengerConfig($value['messenger']); unset($value['messenger']); } @@ -64,10 +69,10 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->translator) { + if (isset($this->_usedProperties['translator'])) { $output['translator'] = $this->translator->toArray(); } - if (null !== $this->messenger) { + if (isset($this->_usedProperties['messenger'])) { $output['messenger'] = $this->messenger->toArray(); } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.output.php index d1bdedcf8a23f..d2fdc1ef5c8e4 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.output.php @@ -20,6 +20,7 @@ 'corge' => 'bar2_corge', 'grault' => 'bar2_grault', 'extra1' => 'bar2_extra1', + 'extra4' => null, 'extra2' => 'bar2_extra2', 'extra3' => 'bar2_extra3', ], diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BarConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BarConfig.php index 87eba94c6b91f..256454f164bbf 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BarConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BarConfig.php @@ -7,12 +7,13 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class BarConfig { private $corge; private $grault; + private $_usedProperties = []; private $_extraKeys; /** @@ -22,6 +23,7 @@ class BarConfig */ public function corge($value): self { + $this->_usedProperties['corge'] = true; $this->corge = $value; return $this; @@ -34,6 +36,7 @@ public function corge($value): self */ public function grault($value): self { + $this->_usedProperties['grault'] = true; $this->grault = $value; return $this; @@ -42,12 +45,14 @@ public function grault($value): self public function __construct(array $value = []) { - if (isset($value['corge'])) { + if (array_key_exists('corge', $value)) { + $this->_usedProperties['corge'] = true; $this->corge = $value['corge']; unset($value['corge']); } - if (isset($value['grault'])) { + if (array_key_exists('grault', $value)) { + $this->_usedProperties['grault'] = true; $this->grault = $value['grault']; unset($value['grault']); } @@ -59,10 +64,10 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->corge) { + if (isset($this->_usedProperties['corge'])) { $output['corge'] = $this->corge; } - if (null !== $this->grault) { + if (isset($this->_usedProperties['grault'])) { $output['grault'] = $this->grault; } @@ -75,11 +80,7 @@ public function toArray(): array */ public function set(string $key, $value): self { - if (null === $value) { - unset($this->_extraKeys[$key]); - } else { - $this->_extraKeys[$key] = $value; - } + $this->_extraKeys[$key] = $value; return $this; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BazConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BazConfig.php index fae09098ab103..d64633eab9c66 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BazConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/BazConfig.php @@ -7,7 +7,7 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class BazConfig { @@ -33,11 +33,7 @@ public function toArray(): array */ public function set(string $key, $value): self { - if (null === $value) { - unset($this->_extraKeys[$key]); - } else { - $this->_extraKeys[$key] = $value; - } + $this->_extraKeys[$key] = $value; return $this; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/FooConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/FooConfig.php index 46632c7f9a0e7..c8f713341eda3 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/FooConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeys/FooConfig.php @@ -7,12 +7,13 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class FooConfig { private $baz; private $qux; + private $_usedProperties = []; private $_extraKeys; /** @@ -22,6 +23,7 @@ class FooConfig */ public function baz($value): self { + $this->_usedProperties['baz'] = true; $this->baz = $value; return $this; @@ -34,6 +36,7 @@ public function baz($value): self */ public function qux($value): self { + $this->_usedProperties['qux'] = true; $this->qux = $value; return $this; @@ -42,12 +45,14 @@ public function qux($value): self public function __construct(array $value = []) { - if (isset($value['baz'])) { + if (array_key_exists('baz', $value)) { + $this->_usedProperties['baz'] = true; $this->baz = $value['baz']; unset($value['baz']); } - if (isset($value['qux'])) { + if (array_key_exists('qux', $value)) { + $this->_usedProperties['qux'] = true; $this->qux = $value['qux']; unset($value['qux']); } @@ -59,10 +64,10 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->baz) { + if (isset($this->_usedProperties['baz'])) { $output['baz'] = $this->baz; } - if (null !== $this->qux) { + if (isset($this->_usedProperties['qux'])) { $output['qux'] = $this->qux; } @@ -75,11 +80,7 @@ public function toArray(): array */ public function set(string $key, $value): self { - if (null === $value) { - unset($this->_extraKeys[$key]); - } else { - $this->_extraKeys[$key] = $value; - } + $this->_extraKeys[$key] = $value; return $this; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeysConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeysConfig.php index 20ff730475f54..3d8adb7095b33 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeysConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys/Symfony/Config/ArrayExtraKeysConfig.php @@ -10,17 +10,19 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class ArrayExtraKeysConfig implements \Symfony\Component\Config\Builder\ConfigBuilderInterface { private $foo; private $bar; private $baz; + private $_usedProperties = []; public function foo(array $value = []): \Symfony\Config\ArrayExtraKeys\FooConfig { if (null === $this->foo) { + $this->_usedProperties['foo'] = true; $this->foo = new \Symfony\Config\ArrayExtraKeys\FooConfig($value); } elseif ([] !== $value) { throw new InvalidConfigurationException('The node created by "foo()" has already been initialized. You cannot pass values the second time you call foo().'); @@ -31,12 +33,15 @@ public function foo(array $value = []): \Symfony\Config\ArrayExtraKeys\FooConfig public function bar(array $value = []): \Symfony\Config\ArrayExtraKeys\BarConfig { + $this->_usedProperties['bar'] = true; + return $this->bar[] = new \Symfony\Config\ArrayExtraKeys\BarConfig($value); } public function baz(array $value = []): \Symfony\Config\ArrayExtraKeys\BazConfig { if (null === $this->baz) { + $this->_usedProperties['baz'] = true; $this->baz = new \Symfony\Config\ArrayExtraKeys\BazConfig($value); } elseif ([] !== $value) { throw new InvalidConfigurationException('The node created by "baz()" has already been initialized. You cannot pass values the second time you call baz().'); @@ -53,17 +58,20 @@ public function getExtensionAlias(): string public function __construct(array $value = []) { - if (isset($value['foo'])) { + if (array_key_exists('foo', $value)) { + $this->_usedProperties['foo'] = true; $this->foo = new \Symfony\Config\ArrayExtraKeys\FooConfig($value['foo']); unset($value['foo']); } - if (isset($value['bar'])) { + if (array_key_exists('bar', $value)) { + $this->_usedProperties['bar'] = true; $this->bar = array_map(function ($v) { return new \Symfony\Config\ArrayExtraKeys\BarConfig($v); }, $value['bar']); unset($value['bar']); } - if (isset($value['baz'])) { + if (array_key_exists('baz', $value)) { + $this->_usedProperties['baz'] = true; $this->baz = new \Symfony\Config\ArrayExtraKeys\BazConfig($value['baz']); unset($value['baz']); } @@ -76,13 +84,13 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->foo) { + if (isset($this->_usedProperties['foo'])) { $output['foo'] = $this->foo->toArray(); } - if (null !== $this->bar) { + if (isset($this->_usedProperties['bar'])) { $output['bar'] = array_map(function ($v) { return $v->toArray(); }, $this->bar); } - if (null !== $this->baz) { + if (isset($this->_usedProperties['baz'])) { $output['baz'] = $this->baz->toArray(); } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.config.php index c51bd764e00e6..4b86755c91a5b 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.config.php @@ -3,7 +3,7 @@ use Symfony\Config\NodeInitialValuesConfig; return static function (NodeInitialValuesConfig $config) { - $config->someCleverName(['second' => 'foo'])->first('bar'); + $config->someCleverName(['second' => 'foo', 'third' => null])->first('bar'); $config->messenger() ->transports('fast_queue', ['dsn' => 'sync://']) ->serializer('acme'); diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.output.php index ec8fee9a6d1d1..7fe70f9645b9e 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.output.php @@ -4,6 +4,7 @@ 'some_clever_name' => [ 'first' => 'bar', 'second' => 'foo', + 'third' => null, ], 'messenger' => [ 'transports' => [ diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.php index 13fdf1ae81d13..c290cf9730670 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.php @@ -17,6 +17,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->children() ->scalarNode('first')->end() ->scalarNode('second')->end() + ->scalarNode('third')->end() ->end() ->end() diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/Messenger/TransportsConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/Messenger/TransportsConfig.php index a3fe5218f0678..3acc0247ac726 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/Messenger/TransportsConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/Messenger/TransportsConfig.php @@ -8,13 +8,14 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class TransportsConfig { private $dsn; private $serializer; private $options; + private $_usedProperties = []; /** * @default null @@ -23,6 +24,7 @@ class TransportsConfig */ public function dsn($value): self { + $this->_usedProperties['dsn'] = true; $this->dsn = $value; return $this; @@ -35,6 +37,7 @@ public function dsn($value): self */ public function serializer($value): self { + $this->_usedProperties['serializer'] = true; $this->serializer = $value; return $this; @@ -46,6 +49,7 @@ public function serializer($value): self */ public function options($value): self { + $this->_usedProperties['options'] = true; $this->options = $value; return $this; @@ -54,17 +58,20 @@ public function options($value): self public function __construct(array $value = []) { - if (isset($value['dsn'])) { + if (array_key_exists('dsn', $value)) { + $this->_usedProperties['dsn'] = true; $this->dsn = $value['dsn']; unset($value['dsn']); } - if (isset($value['serializer'])) { + if (array_key_exists('serializer', $value)) { + $this->_usedProperties['serializer'] = true; $this->serializer = $value['serializer']; unset($value['serializer']); } - if (isset($value['options'])) { + if (array_key_exists('options', $value)) { + $this->_usedProperties['options'] = true; $this->options = $value['options']; unset($value['options']); } @@ -77,13 +84,13 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->dsn) { + if (isset($this->_usedProperties['dsn'])) { $output['dsn'] = $this->dsn; } - if (null !== $this->serializer) { + if (isset($this->_usedProperties['serializer'])) { $output['serializer'] = $this->serializer; } - if (null !== $this->options) { + if (isset($this->_usedProperties['options'])) { $output['options'] = $this->options; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/MessengerConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/MessengerConfig.php index 8e59732f2d024..12ff61109cae7 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/MessengerConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/MessengerConfig.php @@ -8,15 +8,18 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class MessengerConfig { private $transports; + private $_usedProperties = []; public function transports(string $name, array $value = []): \Symfony\Config\NodeInitialValues\Messenger\TransportsConfig { if (!isset($this->transports[$name])) { + $this->_usedProperties['transports'] = true; + return $this->transports[$name] = new \Symfony\Config\NodeInitialValues\Messenger\TransportsConfig($value); } if ([] === $value) { @@ -29,7 +32,8 @@ public function transports(string $name, array $value = []): \Symfony\Config\Nod public function __construct(array $value = []) { - if (isset($value['transports'])) { + if (array_key_exists('transports', $value)) { + $this->_usedProperties['transports'] = true; $this->transports = array_map(function ($v) { return new \Symfony\Config\NodeInitialValues\Messenger\TransportsConfig($v); }, $value['transports']); unset($value['transports']); } @@ -42,7 +46,7 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->transports) { + if (isset($this->_usedProperties['transports'])) { $output['transports'] = array_map(function ($v) { return $v->toArray(); }, $this->transports); } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/SomeCleverNameConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/SomeCleverNameConfig.php index 2db3d4cf95578..3ca87c25eec12 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/SomeCleverNameConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValues/SomeCleverNameConfig.php @@ -8,12 +8,14 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class SomeCleverNameConfig { private $first; private $second; + private $third; + private $_usedProperties = []; /** * @default null @@ -22,6 +24,7 @@ class SomeCleverNameConfig */ public function first($value): self { + $this->_usedProperties['first'] = true; $this->first = $value; return $this; @@ -34,24 +37,46 @@ public function first($value): self */ public function second($value): self { + $this->_usedProperties['second'] = true; $this->second = $value; return $this; } + /** + * @default null + * @param ParamConfigurator|mixed $value + * @return $this + */ + public function third($value): self + { + $this->_usedProperties['third'] = true; + $this->third = $value; + + return $this; + } + public function __construct(array $value = []) { - if (isset($value['first'])) { + if (array_key_exists('first', $value)) { + $this->_usedProperties['first'] = true; $this->first = $value['first']; unset($value['first']); } - if (isset($value['second'])) { + if (array_key_exists('second', $value)) { + $this->_usedProperties['second'] = true; $this->second = $value['second']; unset($value['second']); } + if (array_key_exists('third', $value)) { + $this->_usedProperties['third'] = true; + $this->third = $value['third']; + unset($value['third']); + } + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } @@ -60,12 +85,15 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->first) { + if (isset($this->_usedProperties['first'])) { $output['first'] = $this->first; } - if (null !== $this->second) { + if (isset($this->_usedProperties['second'])) { $output['second'] = $this->second; } + if (isset($this->_usedProperties['third'])) { + $output['third'] = $this->third; + } return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValuesConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValuesConfig.php index d2f8bc654cfde..1ba307fb491eb 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValuesConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues/Symfony/Config/NodeInitialValuesConfig.php @@ -9,16 +9,18 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class NodeInitialValuesConfig implements \Symfony\Component\Config\Builder\ConfigBuilderInterface { private $someCleverName; private $messenger; + private $_usedProperties = []; public function someCleverName(array $value = []): \Symfony\Config\NodeInitialValues\SomeCleverNameConfig { if (null === $this->someCleverName) { + $this->_usedProperties['someCleverName'] = true; $this->someCleverName = new \Symfony\Config\NodeInitialValues\SomeCleverNameConfig($value); } elseif ([] !== $value) { throw new InvalidConfigurationException('The node created by "someCleverName()" has already been initialized. You cannot pass values the second time you call someCleverName().'); @@ -30,6 +32,7 @@ public function someCleverName(array $value = []): \Symfony\Config\NodeInitialVa public function messenger(array $value = []): \Symfony\Config\NodeInitialValues\MessengerConfig { if (null === $this->messenger) { + $this->_usedProperties['messenger'] = true; $this->messenger = new \Symfony\Config\NodeInitialValues\MessengerConfig($value); } elseif ([] !== $value) { throw new InvalidConfigurationException('The node created by "messenger()" has already been initialized. You cannot pass values the second time you call messenger().'); @@ -46,12 +49,14 @@ public function getExtensionAlias(): string public function __construct(array $value = []) { - if (isset($value['some_clever_name'])) { + if (array_key_exists('some_clever_name', $value)) { + $this->_usedProperties['someCleverName'] = true; $this->someCleverName = new \Symfony\Config\NodeInitialValues\SomeCleverNameConfig($value['some_clever_name']); unset($value['some_clever_name']); } - if (isset($value['messenger'])) { + if (array_key_exists('messenger', $value)) { + $this->_usedProperties['messenger'] = true; $this->messenger = new \Symfony\Config\NodeInitialValues\MessengerConfig($value['messenger']); unset($value['messenger']); } @@ -64,10 +69,10 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->someCleverName) { + if (isset($this->_usedProperties['someCleverName'])) { $output['some_clever_name'] = $this->someCleverName->toArray(); } - if (null !== $this->messenger) { + if (isset($this->_usedProperties['messenger'])) { $output['messenger'] = $this->messenger->toArray(); } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders/Symfony/Config/PlaceholdersConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders/Symfony/Config/PlaceholdersConfig.php index 909c95585b441..15fe9b492270d 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders/Symfony/Config/PlaceholdersConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders/Symfony/Config/PlaceholdersConfig.php @@ -8,13 +8,14 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class PlaceholdersConfig implements \Symfony\Component\Config\Builder\ConfigBuilderInterface { private $enabled; private $favoriteFloat; private $goodIntegers; + private $_usedProperties = []; /** * @default false @@ -23,6 +24,7 @@ class PlaceholdersConfig implements \Symfony\Component\Config\Builder\ConfigBuil */ public function enabled($value): self { + $this->_usedProperties['enabled'] = true; $this->enabled = $value; return $this; @@ -35,6 +37,7 @@ public function enabled($value): self */ public function favoriteFloat($value): self { + $this->_usedProperties['favoriteFloat'] = true; $this->favoriteFloat = $value; return $this; @@ -46,6 +49,7 @@ public function favoriteFloat($value): self */ public function goodIntegers($value): self { + $this->_usedProperties['goodIntegers'] = true; $this->goodIntegers = $value; return $this; @@ -59,17 +63,20 @@ public function getExtensionAlias(): string public function __construct(array $value = []) { - if (isset($value['enabled'])) { + if (array_key_exists('enabled', $value)) { + $this->_usedProperties['enabled'] = true; $this->enabled = $value['enabled']; unset($value['enabled']); } - if (isset($value['favorite_float'])) { + if (array_key_exists('favorite_float', $value)) { + $this->_usedProperties['favoriteFloat'] = true; $this->favoriteFloat = $value['favorite_float']; unset($value['favorite_float']); } - if (isset($value['good_integers'])) { + if (array_key_exists('good_integers', $value)) { + $this->_usedProperties['goodIntegers'] = true; $this->goodIntegers = $value['good_integers']; unset($value['good_integers']); } @@ -82,13 +89,13 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->enabled) { + if (isset($this->_usedProperties['enabled'])) { $output['enabled'] = $this->enabled; } - if (null !== $this->favoriteFloat) { + if (isset($this->_usedProperties['favoriteFloat'])) { $output['favorite_float'] = $this->favoriteFloat; } - if (null !== $this->goodIntegers) { + if (isset($this->_usedProperties['goodIntegers'])) { $output['good_integers'] = $this->goodIntegers; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.config.php index 6ca25d66a87c6..b4498957057c4 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.config.php @@ -8,4 +8,5 @@ $config->floatNode(47.11); $config->integerNode(1337); $config->scalarNode('foobar'); + $config->scalarNodeWithDefault(null); }; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.output.php index 6d3e12c5637c4..366fd5c19f4cb 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.output.php @@ -6,4 +6,5 @@ 'float_node' => 47.11, 'integer_node' => 1337, 'scalar_node' => 'foobar', + 'scalar_node_with_default' => null, ]; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.php index aecdbe7953da5..3d36f72bff2db 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.php @@ -18,6 +18,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->floatNode('float_node')->end() ->integerNode('integer_node')->end() ->scalarNode('scalar_node')->end() + ->scalarNode('scalar_node_with_default')->defaultTrue()->end() ->end() ; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes/Symfony/Config/PrimitiveTypesConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes/Symfony/Config/PrimitiveTypesConfig.php index fd802032c28f6..8a1be4e46a204 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes/Symfony/Config/PrimitiveTypesConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes/Symfony/Config/PrimitiveTypesConfig.php @@ -8,7 +8,7 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class PrimitiveTypesConfig implements \Symfony\Component\Config\Builder\ConfigBuilderInterface { @@ -17,6 +17,8 @@ class PrimitiveTypesConfig implements \Symfony\Component\Config\Builder\ConfigBu private $floatNode; private $integerNode; private $scalarNode; + private $scalarNodeWithDefault; + private $_usedProperties = []; /** * @default null @@ -25,6 +27,7 @@ class PrimitiveTypesConfig implements \Symfony\Component\Config\Builder\ConfigBu */ public function booleanNode($value): self { + $this->_usedProperties['booleanNode'] = true; $this->booleanNode = $value; return $this; @@ -37,6 +40,7 @@ public function booleanNode($value): self */ public function enumNode($value): self { + $this->_usedProperties['enumNode'] = true; $this->enumNode = $value; return $this; @@ -49,6 +53,7 @@ public function enumNode($value): self */ public function floatNode($value): self { + $this->_usedProperties['floatNode'] = true; $this->floatNode = $value; return $this; @@ -61,6 +66,7 @@ public function floatNode($value): self */ public function integerNode($value): self { + $this->_usedProperties['integerNode'] = true; $this->integerNode = $value; return $this; @@ -73,11 +79,25 @@ public function integerNode($value): self */ public function scalarNode($value): self { + $this->_usedProperties['scalarNode'] = true; $this->scalarNode = $value; return $this; } + /** + * @default true + * @param ParamConfigurator|mixed $value + * @return $this + */ + public function scalarNodeWithDefault($value): self + { + $this->_usedProperties['scalarNodeWithDefault'] = true; + $this->scalarNodeWithDefault = $value; + + return $this; + } + public function getExtensionAlias(): string { return 'primitive_types'; @@ -86,31 +106,42 @@ public function getExtensionAlias(): string public function __construct(array $value = []) { - if (isset($value['boolean_node'])) { + if (array_key_exists('boolean_node', $value)) { + $this->_usedProperties['booleanNode'] = true; $this->booleanNode = $value['boolean_node']; unset($value['boolean_node']); } - if (isset($value['enum_node'])) { + if (array_key_exists('enum_node', $value)) { + $this->_usedProperties['enumNode'] = true; $this->enumNode = $value['enum_node']; unset($value['enum_node']); } - if (isset($value['float_node'])) { + if (array_key_exists('float_node', $value)) { + $this->_usedProperties['floatNode'] = true; $this->floatNode = $value['float_node']; unset($value['float_node']); } - if (isset($value['integer_node'])) { + if (array_key_exists('integer_node', $value)) { + $this->_usedProperties['integerNode'] = true; $this->integerNode = $value['integer_node']; unset($value['integer_node']); } - if (isset($value['scalar_node'])) { + if (array_key_exists('scalar_node', $value)) { + $this->_usedProperties['scalarNode'] = true; $this->scalarNode = $value['scalar_node']; unset($value['scalar_node']); } + if (array_key_exists('scalar_node_with_default', $value)) { + $this->_usedProperties['scalarNodeWithDefault'] = true; + $this->scalarNodeWithDefault = $value['scalar_node_with_default']; + unset($value['scalar_node_with_default']); + } + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } @@ -119,21 +150,24 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->booleanNode) { + if (isset($this->_usedProperties['booleanNode'])) { $output['boolean_node'] = $this->booleanNode; } - if (null !== $this->enumNode) { + if (isset($this->_usedProperties['enumNode'])) { $output['enum_node'] = $this->enumNode; } - if (null !== $this->floatNode) { + if (isset($this->_usedProperties['floatNode'])) { $output['float_node'] = $this->floatNode; } - if (null !== $this->integerNode) { + if (isset($this->_usedProperties['integerNode'])) { $output['integer_node'] = $this->integerNode; } - if (null !== $this->scalarNode) { + if (isset($this->_usedProperties['scalarNode'])) { $output['scalar_node'] = $this->scalarNode; } + if (isset($this->_usedProperties['scalarNodeWithDefault'])) { + $output['scalar_node_with_default'] = $this->scalarNodeWithDefault; + } return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType/Symfony/Config/VariableTypeConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType/Symfony/Config/VariableTypeConfig.php index 0ee7efe7f362b..a36bf5f31c966 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType/Symfony/Config/VariableTypeConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType/Symfony/Config/VariableTypeConfig.php @@ -8,11 +8,12 @@ /** - * This class is automatically generated to help creating config. + * This class is automatically generated to help in creating a config. */ class VariableTypeConfig implements \Symfony\Component\Config\Builder\ConfigBuilderInterface { private $anyValue; + private $_usedProperties = []; /** * @default null @@ -21,6 +22,7 @@ class VariableTypeConfig implements \Symfony\Component\Config\Builder\ConfigBuil */ public function anyValue($value): self { + $this->_usedProperties['anyValue'] = true; $this->anyValue = $value; return $this; @@ -34,7 +36,8 @@ public function getExtensionAlias(): string public function __construct(array $value = []) { - if (isset($value['any_value'])) { + if (array_key_exists('any_value', $value)) { + $this->_usedProperties['anyValue'] = true; $this->anyValue = $value['any_value']; unset($value['any_value']); } @@ -47,7 +50,7 @@ public function __construct(array $value = []) public function toArray(): array { $output = []; - if (null !== $this->anyValue) { + if (isset($this->_usedProperties['anyValue'])) { $output['any_value'] = $this->anyValue; } diff --git a/src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php b/src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php index 83b98d12ac363..e22b3123910ed 100644 --- a/src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php +++ b/src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php @@ -19,6 +19,11 @@ * Test to use the generated config and test its output. * * @author Tobias Nyholm + * + * @covers \Symfony\Component\Config\Builder\ClassBuilder + * @covers \Symfony\Component\Config\Builder\ConfigBuilderGenerator + * @covers \Symfony\Component\Config\Builder\Method + * @covers \Symfony\Component\Config\Builder\Property */ class GeneratedConfigTest extends TestCase { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy