From d0d665cf29fad28e3aa984eb8d55843b95fec0d9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 14 May 2022 20:42:07 +0200 Subject: [PATCH 01/48] Bump Symfony version to 6.1.0 --- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 603365b81c3b5..aafc62dbb01f9 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -78,12 +78,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.1.0-RC1'; + public const VERSION = '6.1.0-DEV'; public const VERSION_ID = 60100; public const MAJOR_VERSION = 6; public const MINOR_VERSION = 1; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'RC1'; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '01/2023'; public const END_OF_LIFE = '01/2023'; From c20659196d6fd5e7c7bb12444b6d224bcf68757f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 16 May 2022 18:49:05 +0200 Subject: [PATCH 02/48] Revert "bug #46327 [HttpKernel] Allow ErrorHandler ^5.0 to be used in HttpKernel 4.4 (mpdude)" This reverts commit 1e317ccd651085920e4eb4a68f3eb4aaef066ed9, reversing changes made to 129a2710e6c884bdbed77eb18760904455633ce7. --- src/Symfony/Component/HttpKernel/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index 8111f72b46b2f..c2758e45ae8cc 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=7.1.3", - "symfony/error-handler": "^4.4|^5.0", + "symfony/error-handler": "^4.4", "symfony/event-dispatcher": "^4.4", "symfony/http-client-contracts": "^1.1|^2", "symfony/http-foundation": "^4.4.30|^5.3.7", From d4ea07272644d89a04149a10d0b93d73aefcfd0d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 16 May 2022 17:15:26 +0200 Subject: [PATCH 03/48] [Config] Fix looking for single files in phars with GlobResource --- .../Config/Resource/GlobResource.php | 17 +++++++++--- .../Component/Config/Tests/Fixtures/some.phar | Bin 0 -> 1185 bytes .../Tests/Resource/GlobResourceTest.php | 25 ++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/Symfony/Component/Config/Tests/Fixtures/some.phar diff --git a/src/Symfony/Component/Config/Resource/GlobResource.php b/src/Symfony/Component/Config/Resource/GlobResource.php index 3657f6dcb9500..57e528462cc90 100644 --- a/src/Symfony/Component/Config/Resource/GlobResource.php +++ b/src/Symfony/Component/Config/Resource/GlobResource.php @@ -111,7 +111,9 @@ public function getIterator() $prefix = str_replace('\\', '/', $this->prefix); $paths = null; - if (!str_starts_with($this->prefix, 'phar://') && !str_contains($this->pattern, '/**/')) { + if ('' === $this->pattern && is_file($prefix)) { + $paths = [$this->prefix]; + } elseif (!str_starts_with($this->prefix, 'phar://') && !str_contains($this->pattern, '/**/')) { if ($this->globBrace || !str_contains($this->pattern, '{')) { $paths = glob($this->prefix.$this->pattern, \GLOB_NOSORT | $this->globBrace); } elseif (!str_contains($this->pattern, '\\') || !preg_match('/\\\\[,{}]/', $this->pattern)) { @@ -172,14 +174,21 @@ function (\SplFileInfo $file, $path) { throw new \LogicException(sprintf('Extended glob pattern "%s" cannot be used as the Finder component is not installed.', $this->pattern)); } + if (is_file($prefix = $this->prefix)) { + $prefix = \dirname($prefix); + $pattern = basename($prefix).$this->pattern; + } else { + $pattern = $this->pattern; + } + $finder = new Finder(); - $regex = Glob::toRegex($this->pattern); + $regex = Glob::toRegex($pattern); if ($this->recursive) { $regex = substr_replace($regex, '(/|$)', -2, 1); } - $prefixLen = \strlen($this->prefix); - foreach ($finder->followLinks()->sortByName()->in($this->prefix) as $path => $info) { + $prefixLen = \strlen($prefix); + foreach ($finder->followLinks()->sortByName()->in($prefix) as $path => $info) { $normalizedPath = str_replace('\\', '/', $path); if (!preg_match($regex, substr($normalizedPath, $prefixLen)) || !$info->isFile()) { continue; diff --git a/src/Symfony/Component/Config/Tests/Fixtures/some.phar b/src/Symfony/Component/Config/Tests/Fixtures/some.phar new file mode 100644 index 0000000000000000000000000000000000000000..93d4e87c0b89b6295ecf024eb6ec7dc8c30c0f05 GIT binary patch literal 1185 zcmb7Dzi-n(6n2@AB?cDe0__6U#eRv6?DO^ROoC817Dh&9 z7}@v(m|0n2;D113VB(#fgjNDvPP#km?tS08_kGW;u80H~MNE2L%7po-(~-=cLZFXg z9UZH1f1!b^IOBb8t{s63-E0yGCwVNv&v*cYnp4kptD%)4f;Nfo-`g3C{W}N4QGc+1 zSjTkT&K3KuWm%VSUd6d#QCzF@VUTtG0+Hh7hGl(w{p7LP4?ceR@eX%0uHjTc1SxYx zDa_Wk({L6le7{7PUCLK$M9YY3+d;yVBL93L0V8g>j#_JNzpx1okx!C1Ak&-&8XX`r z(CEk`mc$`52fIwci0P=l=@F%6%x49x1RDYgI+q;v-0L6uzEg9{N@~p_?$rKUmisIP zC0GDe%(X~sfyU40a|aeI6$v;&mM-(G6q{o!pvC#xN6h?FNqd97H|*w&QZ*7I+>ig zHyVv?_jovXP_$AB&`hGEYpu`0E+}S61PP?TbuW|Y9!y!D=r%pcu}!8igcPeJq^NTl zM>yKsrW5>;iGD6tpYHEKv=E(KjPdeJaHlAassertEquals($p->getValue($resource), $p->getValue($newResource)); } + + public function testPhar() + { + $s = \DIRECTORY_SEPARATOR; + $cwd = getcwd(); + chdir(\dirname(__DIR__).'/Fixtures'); + try { + $resource = new GlobResource('phar://some.phar', '*', true); + $files = array_keys(iterator_to_array($resource)); + $this->assertSame(["phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php", "phar://some.phar{$s}schema{$s}project-1.0.xsd"], $files); + + $resource = new GlobResource("phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php", '', true); + $files = array_keys(iterator_to_array($resource)); + $this->assertSame(["phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php"], $files); + } finally { + chdir($cwd); + } + } + + public function testFilePrefix() + { + $resource = new GlobResource(__FILE__, '/**/', true); + $files = array_keys(iterator_to_array($resource)); + $this->assertSame([], $files); + } } From 8ce55aefb2bfbac9436a1fea8e1b358a1f84a2d9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 17 May 2022 09:25:31 +0200 Subject: [PATCH 04/48] [VarDumper] fix test on PHP 8.2 --- .../Component/VarDumper/Tests/Caster/ReflectionCasterTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php index 3dae54ce46b33..b7bccc0bdcda6 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php @@ -38,11 +38,11 @@ public function testReflectionCaster() +name: "ReflectionClass" %Aimplements: array:%d [ %A] - constants: array:3 [ + constants: array:%d [ "IS_IMPLICIT_ABSTRACT" => 16 "IS_EXPLICIT_ABSTRACT" => %d "IS_FINAL" => %d - ] +%A] properties: array:%d [ "name" => ReflectionProperty { %A +name: "name" From 410d7f2587462b9842ed3a73ac31d09d0fb32f01 Mon Sep 17 00:00:00 2001 From: BoShurik Date: Mon, 16 May 2022 12:52:52 +0300 Subject: [PATCH 05/48] [PropertyInfo] Ignore empty doc-block for promoted properties in PhpStanExtractor --- .../Extractor/PhpStanExtractor.php | 6 ++++- .../Tests/Extractor/PhpStanExtractorTest.php | 8 ++++--- .../Tests/Fixtures/Php80PromotedDummy.php | 24 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80PromotedDummy.php diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php index db25e14f44736..d00b81e5f17d0 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php @@ -227,7 +227,11 @@ private function getDocBlockFromProperty(string $class, string $property): ?arra $constructor = new \ReflectionMethod($class, '__construct'); $rawDocNode = $constructor->getDocComment(); $source = self::MUTATOR; - } elseif (null === $rawDocNode = $reflectionProperty->getDocComment() ?: null) { + } else { + $rawDocNode = $reflectionProperty->getDocComment(); + } + + if (!$rawDocNode) { return null; } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php index 0cf346fce03c1..9edea0725481a 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php @@ -18,6 +18,7 @@ use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80Dummy; +use Symfony\Component\PropertyInfo\Tests\Fixtures\Php80PromotedDummy; use Symfony\Component\PropertyInfo\Tests\Fixtures\RootDummy\RootDummyItem; use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait; use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsingTrait; @@ -439,15 +440,16 @@ public function testDummyNamespaceWithProperty() /** * @dataProvider php80TypesProvider */ - public function testExtractPhp80Type($property, array $type = null) + public function testExtractPhp80Type(string $class, $property, array $type = null) { - $this->assertEquals($type, $this->extractor->getTypes(Php80Dummy::class, $property, [])); + $this->assertEquals($type, $this->extractor->getTypes($class, $property, [])); } public function php80TypesProvider() { return [ - ['promotedAndMutated', [new Type(Type::BUILTIN_TYPE_STRING)]], + [Php80Dummy::class, 'promotedAndMutated', [new Type(Type::BUILTIN_TYPE_STRING)]], + [Php80PromotedDummy::class, 'promoted', null], ]; } } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80PromotedDummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80PromotedDummy.php new file mode 100644 index 0000000000000..f612df99e2ba4 --- /dev/null +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80PromotedDummy.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyInfo\Tests\Fixtures; + +class Php80PromotedDummy +{ + public function __construct(private string $promoted) + { + } + + public function getPromoted(): string + { + return $this->promoted; + } +} From 17e563ba1b83d488b03d6eda7c69a9fe8daa331f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 17 May 2022 10:53:34 +0200 Subject: [PATCH 06/48] [PropertyInfo] CS fixes --- .../PropertyInfo/Tests/Fixtures/DockBlockFallback.php | 2 -- .../PropertyInfo/Tests/Fixtures/NoProperties.php | 2 -- .../Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php | 9 +++++++++ .../Component/PropertyInfo/Tests/Fixtures/Php81Dummy.php | 9 +++++++++ .../PropertyInfo/Tests/Fixtures/PseudoTypeDummy.php | 9 +++++++++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DockBlockFallback.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DockBlockFallback.php index 3f9c303b59137..6379e6cea8eb9 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DockBlockFallback.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DockBlockFallback.php @@ -1,7 +1,5 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\PropertyInfo\Tests\Fixtures; class Php80Dummy diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php81Dummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php81Dummy.php index 1300c3e695f1f..842f59fbfd47b 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php81Dummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php81Dummy.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\PropertyInfo\Tests\Fixtures; class Php81Dummy diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/PseudoTypeDummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/PseudoTypeDummy.php index 71756044fafc9..d2efecef9dcf4 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/PseudoTypeDummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/PseudoTypeDummy.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\PropertyInfo\Tests\Fixtures; class PseudoTypeDummy From 09f47f4a604911ca0de2a29899f362852e523a65 Mon Sep 17 00:00:00 2001 From: Xesau Date: Mon, 16 May 2022 09:32:48 +0200 Subject: [PATCH 07/48] Add approriate description to CollectionToArrayTransformer::reverseTransform docblock --- .../Form/DataTransformer/CollectionToArrayTransformer.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php b/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php index 3202dae97f5c2..d8235a681479f 100644 --- a/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php +++ b/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php @@ -24,8 +24,6 @@ class CollectionToArrayTransformer implements DataTransformerInterface /** * Transforms a collection into an array. * - * @return mixed An array of entities - * * @throws TransformationFailedException */ public function transform($collection) @@ -48,11 +46,9 @@ public function transform($collection) } /** - * Transforms choice keys into entities. - * - * @param mixed $array An array of entities + * Transforms an array into a collection. * - * @return Collection A collection of entities + * @return Collection */ public function reverseTransform($array) { From a6ec67512e13ff3f42267db13361e0c68c4af547 Mon Sep 17 00:00:00 2001 From: Chris W Jones Date: Mon, 16 May 2022 14:59:02 -0400 Subject: [PATCH 08/48] [Mime] Add null check for EmailHeaderSame --- .../Mime/Test/Constraint/EmailHeaderSame.php | 8 +++++--- src/Symfony/Component/Mime/Tests/EmailTest.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php b/src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php index 74bdc63c79f71..74b412183a779 100644 --- a/src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php +++ b/src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php @@ -55,12 +55,14 @@ protected function matches($message): bool */ protected function failureDescription($message): string { - return sprintf('the Email %s (value is %s)', $this->toString(), $this->getHeaderValue($message)); + return sprintf('the Email %s (value is %s)', $this->toString(), $this->getHeaderValue($message) ?? 'null'); } - private function getHeaderValue($message): string + private function getHeaderValue($message): ?string { - $header = $message->getHeaders()->get($this->headerName); + if (null === $header = $message->getHeaders()->get($this->headerName)) { + return null; + } return $header instanceof UnstructuredHeader ? $header->getValue() : $header->getBodyAsString(); } diff --git a/src/Symfony/Component/Mime/Tests/EmailTest.php b/src/Symfony/Component/Mime/Tests/EmailTest.php index 230df0791e15b..baffa4a4e0655 100644 --- a/src/Symfony/Component/Mime/Tests/EmailTest.php +++ b/src/Symfony/Component/Mime/Tests/EmailTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Mime\Tests; +use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Email; @@ -19,6 +20,7 @@ use Symfony\Component\Mime\Part\Multipart\MixedPart; use Symfony\Component\Mime\Part\Multipart\RelatedPart; use Symfony\Component\Mime\Part\TextPart; +use Symfony\Component\Mime\Test\Constraint\EmailHeaderSame; class EmailTest extends TestCase { @@ -384,4 +386,14 @@ public function testSerialize() $this->assertEquals($expected->getHeaders(), $n->getHeaders()); $this->assertEquals($e->getBody(), $n->getBody()); } + + public function testMissingHeaderDoesNotThrowError() + { + $this->expectException(ExpectationFailedException::class); + $this->expectExceptionMessage('Failed asserting that the Email has header "foo" with value "bar" (value is null).'); + + $e = new Email(); + $emailHeaderSame = new EmailHeaderSame('foo', 'bar'); + $emailHeaderSame->evaluate($e); + } } From 1ec8c1edcb0c2810f29c06b951cffb07ae6f4040 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 17 May 2022 11:48:49 +0200 Subject: [PATCH 09/48] [VarDumper] fix tests on PHP 8.2 --- .../Component/VarDumper/Tests/Caster/ReflectionCasterTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php index c261a0da8c168..ebdfa3b21d40b 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php @@ -39,7 +39,7 @@ public function testReflectionCaster() +name: "ReflectionClass" %Aimplements: array:%d [ %A] - constants: array:3 [ + constants: array:%d [ 0 => ReflectionClassConstant { +name: "IS_IMPLICIT_ABSTRACT" +class: "ReflectionClass" @@ -58,7 +58,7 @@ public function testReflectionCaster() modifiers: "public" value: %d } - ] +%A] properties: array:%d [ "name" => ReflectionProperty { %A +name: "name" From 1c176e160396d5f60ea9363fbcdfd9c074fd3671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Sat, 20 Nov 2021 19:20:10 +0100 Subject: [PATCH 10/48] [Config] Allow scalar configuration in PHP Configuration --- .../Config/Builder/ConfigBuilderGenerator.php | 3 +- .../Tests/Builder/Fixtures/Placeholders.php | 2 +- .../Fixtures/ScalarNormalizedTypes.config.php | 12 +++ .../Fixtures/ScalarNormalizedTypes.output.php | 13 ++++ .../Fixtures/ScalarNormalizedTypes.php | 77 +++++++++++++++++++ .../Tests/Builder/GeneratedConfigTest.php | 1 + 6 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.config.php create mode 100644 src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.output.php create mode 100644 src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.php diff --git a/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php b/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php index 920f12104f3a6..1a47a13b8085b 100644 --- a/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php +++ b/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php @@ -435,8 +435,7 @@ private function buildConstructor(ClassBuilder $class): void $class->addMethod('__construct', ' public function __construct(array $value = []) -{ -'.$body.' +{'.$body.' }'); } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.php index 78baa477355e7..6735b5e955675 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.php @@ -15,7 +15,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->children() ->booleanNode('enabled')->defaultFalse()->end() ->floatNode('favorite_float')->end() - ->arrayNode('good_integers') + ->arrayNode('good_integers') ->integerPrototype()->end() ->end() ->end() diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.config.php new file mode 100644 index 0000000000000..e7553fc94f17b --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.config.php @@ -0,0 +1,12 @@ +simpleArray('foo') + ->keyedArray('key', 'value') + ->listObject('bar') + ->listObject('baz') + ->listObject()->name('qux'); +}; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.output.php new file mode 100644 index 0000000000000..ae84a56709062 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.output.php @@ -0,0 +1,13 @@ + 'foo', + 'keyed_array' => [ + 'key' => 'value' + ], + 'list_object' => [ + 'bar', + 'baz', + ['name' => 'qux'], + ], +]; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.php new file mode 100644 index 0000000000000..c33edeb4f062e --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.php @@ -0,0 +1,77 @@ +getRootNode(); + $rootNode + ->children() + ->arrayNode('simple_array') + ->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end() + ->prototype('scalar')->end() + ->end() + ->arrayNode('keyed_array') + ->useAttributeAsKey('name') + ->prototype('array') + ->beforeNormalization() + ->ifString()->then(function ($v) { return [$v]; }) + ->end() + ->prototype('scalar')->end() + ->end() + ->end() + ->arrayNode('list_object') + ->beforeNormalization() + ->always() + ->then(function ($values) { + //inspired by Workflow places + if (isset($values[0]) && \is_string($values[0])) { + return array_map(function (string $value) { + return ['name' => $value]; + }, $values); + } + + if (isset($values[0]) && \is_array($values[0])) { + return $values; + } + + foreach ($values as $name => $value) { + if (\is_array($value) && \array_key_exists('name', $value)) { + continue; + } + $value['name'] = $name; + $values[$name] = $value; + } + + return array_values($values); + }) + ->end() + ->isRequired() + ->requiresAtLeastOneElement() + ->prototype('array') + ->children() + ->scalarNode('name') + ->isRequired() + ->cannotBeEmpty() + ->end() + ->arrayNode('data') + ->normalizeKeys(false) + ->defaultValue([]) + ->prototype('variable') + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ; + + return $tb; + } +} diff --git a/src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php b/src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php index 9def6476b57dd..03f5cd43db87d 100644 --- a/src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php +++ b/src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php @@ -56,6 +56,7 @@ protected function tearDown(): void public function fixtureNames() { $array = [ + 'ScalarNormalizedTypes' => 'scalar_normalized_types', 'PrimitiveTypes' => 'primitive_types', 'VariableType' => 'variable_type', 'AddToList' => 'add_to_list', From 2d81a3a89c8908b3901b9731733bb13bccd25000 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Wed, 11 May 2022 17:42:58 +0200 Subject: [PATCH 11/48] [Config] Allow scalar configuration in PHP Configuration --- .../Component/Config/Builder/ClassBuilder.php | 8 +- .../Config/Builder/ConfigBuilderGenerator.php | 126 ++++++++++-- .../Component/Config/Builder/Property.php | 11 + .../Builder/Fixtures/AddToList.config.php | 9 + .../Builder/Fixtures/AddToList.output.php | 9 + .../Tests/Builder/Fixtures/AddToList.php | 9 + .../AddToList/Messenger/ReceivingConfig.php | 21 +- .../AddToList/Messenger/RoutingConfig.php | 15 +- .../Config/AddToList/MessengerConfig.php | 30 ++- .../Config/AddToList/TranslatorConfig.php | 21 +- .../Symfony/Config/AddToListConfig.php | 26 ++- .../Fixtures/ArrayExtraKeys.config.php | 9 + .../Fixtures/ArrayExtraKeys.output.php | 9 + .../Tests/Builder/Fixtures/ArrayExtraKeys.php | 9 + .../Config/ArrayExtraKeys/BarConfig.php | 27 ++- .../Config/ArrayExtraKeys/BazConfig.php | 15 +- .../Config/ArrayExtraKeys/FooConfig.php | 27 ++- .../Symfony/Config/ArrayExtraKeysConfig.php | 32 ++- .../Fixtures/NodeInitialValues.config.php | 9 + .../Fixtures/NodeInitialValues.output.php | 9 + .../Builder/Fixtures/NodeInitialValues.php | 9 + .../Messenger/TransportsConfig.php | 27 ++- .../NodeInitialValues/MessengerConfig.php | 24 +-- .../SomeCleverNameConfig.php | 27 ++- .../Config/NodeInitialValuesConfig.php | 26 ++- .../Builder/Fixtures/Placeholders.config.php | 9 + .../Builder/Fixtures/Placeholders.output.php | 9 + .../Tests/Builder/Fixtures/Placeholders.php | 9 + .../Symfony/Config/PlaceholdersConfig.php | 29 ++- .../Fixtures/PrimitiveTypes.config.php | 9 + .../Fixtures/PrimitiveTypes.output.php | 9 + .../Tests/Builder/Fixtures/PrimitiveTypes.php | 9 + .../Symfony/Config/PrimitiveTypesConfig.php | 47 ++--- .../Fixtures/ScalarNormalizedTypes.config.php | 19 ++ .../Fixtures/ScalarNormalizedTypes.output.php | 22 +- .../Fixtures/ScalarNormalizedTypes.php | 91 ++++++-- .../KeyedListObjectConfig.php | 74 +++++++ .../ListObjectConfig.php | 74 +++++++ .../Nested/NestedListObjectConfig.php | 52 +++++ .../Nested/NestedObjectConfig.php | 52 +++++ .../ScalarNormalizedTypes/NestedConfig.php | 88 ++++++++ .../ScalarNormalizedTypes/ObjectConfig.php | 98 +++++++++ .../Config/ScalarNormalizedTypesConfig.php | 194 ++++++++++++++++++ .../Builder/Fixtures/VariableType.config.php | 9 + .../Builder/Fixtures/VariableType.output.php | 9 + .../Tests/Builder/Fixtures/VariableType.php | 9 + .../Symfony/Config/VariableTypeConfig.php | 17 +- 47 files changed, 1218 insertions(+), 264 deletions(-) create mode 100644 src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/KeyedListObjectConfig.php create mode 100644 src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ListObjectConfig.php create mode 100644 src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedListObjectConfig.php create mode 100644 src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedObjectConfig.php create mode 100644 src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/NestedConfig.php create mode 100644 src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ObjectConfig.php create mode 100644 src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypesConfig.php diff --git a/src/Symfony/Component/Config/Builder/ClassBuilder.php b/src/Symfony/Component/Config/Builder/ClassBuilder.php index 82fadf691f69d..9960d650806a4 100644 --- a/src/Symfony/Component/Config/Builder/ClassBuilder.php +++ b/src/Symfony/Component/Config/Builder/ClassBuilder.php @@ -68,7 +68,7 @@ public function build(): string } $require .= sprintf('require_once __DIR__.\DIRECTORY_SEPARATOR.\'%s\';', implode('\'.\DIRECTORY_SEPARATOR.\'', $path))."\n"; } - $use = ''; + $use = $require ? "\n" : ''; foreach (array_keys($this->use) as $statement) { $use .= sprintf('use %s;', $statement)."\n"; } @@ -81,7 +81,7 @@ public function build(): string foreach ($this->methods as $method) { $lines = explode("\n", $method->getContent()); foreach ($lines as $line) { - $body .= ' '.$line."\n"; + $body .= ($line ? ' '.$line : '')."\n"; } } @@ -89,9 +89,7 @@ public function build(): string namespace NAMESPACE; -REQUIRE -USE - +REQUIREUSE /** * This class is automatically generated to help in creating a config. */ diff --git a/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php b/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php index 1a47a13b8085b..c63917bcb0eaa 100644 --- a/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php +++ b/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php @@ -136,14 +136,39 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n $class->addRequire($childClass); $this->classes[] = $childClass; - $property = $class->addProperty($node->getName(), $childClass->getFqcn()); - $body = ' + $hasNormalizationClosures = $this->hasNormalizationClosures($node); + $property = $class->addProperty( + $node->getName(), + $this->getType($childClass->getFqcn(), $hasNormalizationClosures) + ); + $body = $hasNormalizationClosures ? ' +/** + * @return CLASS|$this + */ +public function NAME($value = []) +{ + if (!\is_array($value)) { + $this->_usedProperties[\'PROPERTY\'] = true; + $this->PROPERTY = $value; + + return $this; + } + + if (!$this->PROPERTY instanceof CLASS) { + $this->_usedProperties[\'PROPERTY\'] = true; + $this->PROPERTY = new CLASS($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\'); + } + + return $this->PROPERTY; +}' : ' public function NAME(array $value = []): CLASS { if (null === $this->PROPERTY) { $this->_usedProperties[\'PROPERTY\'] = true; $this->PROPERTY = new CLASS($value); - } elseif ([] !== $value) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\'); } @@ -227,10 +252,29 @@ public function NAME(string $VAR, $VALUE): self } $class->addRequire($childClass); $this->classes[] = $childClass; - $property = $class->addProperty($node->getName(), $childClass->getFqcn().'[]'); + + $hasNormalizationClosures = $this->hasNormalizationClosures($node) || $this->hasNormalizationClosures($prototype); + $property = $class->addProperty( + $node->getName(), + $this->getType($childClass->getFqcn().'[]', $hasNormalizationClosures) + ); if (null === $key = $node->getKeyAttribute()) { - $body = ' + $body = $hasNormalizationClosures ? ' +/** + * @return CLASS|$this + */ +public function NAME($value = []) +{ + $this->_usedProperties[\'PROPERTY\'] = true; + if (!\is_array($value)) { + $this->PROPERTY[] = $value; + + return $this; + } + + return $this->PROPERTY[] = new CLASS($value); +}' : ' public function NAME(array $value = []): CLASS { $this->_usedProperties[\'PROPERTY\'] = true; @@ -239,19 +283,38 @@ public function NAME(array $value = []): CLASS }'; $class->addMethod($methodName, $body, ['PROPERTY' => $property->getName(), 'CLASS' => $childClass->getFqcn()]); } else { - $body = ' -public function NAME(string $VAR, array $VALUE = []): CLASS + $body = $hasNormalizationClosures ? ' +/** + * @return CLASS|$this + */ +public function NAME(string $VAR, $VALUE = []) { - if (!isset($this->PROPERTY[$VAR])) { + if (!\is_array($VALUE)) { $this->_usedProperties[\'PROPERTY\'] = true; + $this->PROPERTY[$VAR] = $VALUE; - return $this->PROPERTY[$VAR] = new CLASS($VALUE); + return $this; } - if ([] === $VALUE) { - return $this->PROPERTY[$VAR]; + + if (!isset($this->PROPERTY[$VAR]) || !$this->PROPERTY[$VAR] instanceof CLASS) { + $this->_usedProperties[\'PROPERTY\'] = true; + $this->PROPERTY[$VAR] = new CLASS($VALUE); + } elseif (1 < \func_num_args()) { + throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\'); + } + + return $this->PROPERTY[$VAR]; +}' : ' +public function NAME(string $VAR, array $VALUE = []): CLASS +{ + if (!isset($this->PROPERTY[$VAR])) { + $this->_usedProperties[\'PROPERTY\'] = true; + $this->PROPERTY[$VAR] = new CLASS($VALUE); + } elseif (1 < \func_num_args()) { + throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\'); } - throw new InvalidConfigurationException(\'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME().\'); + return $this->PROPERTY[$VAR]; }'; $class->addUse(InvalidConfigurationException::class); $class->addMethod($methodName, $body, ['PROPERTY' => $property->getName(), 'CLASS' => $childClass->getFqcn(), 'VAR' => '' === $key ? 'key' : $key, 'VALUE' => 'value' === $key ? 'data' : 'value']); @@ -375,16 +438,22 @@ private function buildToArray(ClassBuilder $class): void $code = '$this->PROPERTY'; if (null !== $p->getType()) { if ($p->isArray()) { - $code = 'array_map(function ($v) { return $v->toArray(); }, $this->PROPERTY)'; + $code = $p->areScalarsAllowed() + ? 'array_map(function ($v) { return $v instanceof CLASS ? $v->toArray() : $v; }, $this->PROPERTY)' + : 'array_map(function ($v) { return $v->toArray(); }, $this->PROPERTY)' + ; } else { - $code = '$this->PROPERTY->toArray()'; + $code = $p->areScalarsAllowed() + ? '$this->PROPERTY instanceof CLASS ? $this->PROPERTY->toArray() : $this->PROPERTY' + : '$this->PROPERTY->toArray()' + ; } } $body .= strtr(' if (isset($this->_usedProperties[\'PROPERTY\'])) { $output[\'ORG_NAME\'] = '.$code.'; - }', ['PROPERTY' => $p->getName(), 'ORG_NAME' => $p->getOriginalName()]); + }', ['PROPERTY' => $p->getName(), 'ORG_NAME' => $p->getOriginalName(), 'CLASS' => $p->getType()]); } $extraKeys = $class->shouldAllowExtraKeys() ? ' + $this->_extraKeys' : ''; @@ -405,9 +474,15 @@ private function buildConstructor(ClassBuilder $class): void $code = '$value[\'ORG_NAME\']'; if (null !== $p->getType()) { if ($p->isArray()) { - $code = 'array_map(function ($v) { return new '.$p->getType().'($v); }, $value[\'ORG_NAME\'])'; + $code = $p->areScalarsAllowed() + ? 'array_map(function ($v) { return \is_array($v) ? new '.$p->getType().'($v) : $v; }, $value[\'ORG_NAME\'])' + : 'array_map(function ($v) { return new '.$p->getType().'($v); }, $value[\'ORG_NAME\'])' + ; } else { - $code = 'new '.$p->getType().'($value[\'ORG_NAME\'])'; + $code = $p->areScalarsAllowed() + ? '\is_array($value[\'ORG_NAME\']) ? new '.$p->getType().'($value[\'ORG_NAME\']) : $value[\'ORG_NAME\']' + : 'new '.$p->getType().'($value[\'ORG_NAME\'])' + ; } } @@ -466,4 +541,21 @@ private function getSubNamespace(ClassBuilder $rootClass): string { return sprintf('%s\\%s', $rootClass->getNamespace(), substr($rootClass->getName(), 0, -6)); } + + private function hasNormalizationClosures(NodeInterface $node): bool + { + try { + $r = new \ReflectionProperty($node, 'normalizationClosures'); + } catch (\ReflectionException $e) { + return false; + } + $r->setAccessible(true); + + return [] !== $r->getValue($node); + } + + private function getType(string $classType, bool $hasNormalizationClosures): string + { + return $classType.($hasNormalizationClosures ? '|scalar' : ''); + } } diff --git a/src/Symfony/Component/Config/Builder/Property.php b/src/Symfony/Component/Config/Builder/Property.php index 1b24c47cc909b..5a6f7e31bfe70 100644 --- a/src/Symfony/Component/Config/Builder/Property.php +++ b/src/Symfony/Component/Config/Builder/Property.php @@ -23,6 +23,7 @@ class Property private $name; private $originalName; private $array = false; + private $scalarsAllowed = false; private $type = null; private $content; @@ -47,6 +48,11 @@ public function setType(string $type): void $this->array = false; $this->type = $type; + if ('|scalar' === substr($type, -7)) { + $this->scalarsAllowed = true; + $this->type = $type = substr($type, 0, -7); + } + if ('[]' === substr($type, -2)) { $this->array = true; $this->type = substr($type, 0, -2); @@ -72,4 +78,9 @@ public function isArray(): bool { return $this->array; } + + public function areScalarsAllowed(): bool + { + return $this->scalarsAllowed; + } } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.config.php index 5bb32b89be990..4dc2d3e87ab53 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.config.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Symfony\Config\AddToListConfig; return static function (AddToListConfig $config) { diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.output.php index 6efdb83839604..1949f59c24963 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.output.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'translator' => [ 'fallbacks' => ['sv', 'fr', 'es'], diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.php index 949cbe9e4e5ac..5f324d29cb0b4 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/AddToList.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; 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 c757266195482..5d8d28af443c3 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 @@ -2,11 +2,9 @@ namespace Symfony\Config\AddToList\Messenger; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -15,7 +13,7 @@ class ReceivingConfig private $priority; private $color; private $_usedProperties = []; - + /** * @default null * @param ParamConfigurator|int $value @@ -25,10 +23,10 @@ public function priority($value): self { $this->_usedProperties['priority'] = true; $this->priority = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -38,30 +36,29 @@ public function color($value): self { $this->_usedProperties['color'] = true; $this->color = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('priority', $value)) { $this->_usedProperties['priority'] = true; $this->priority = $value['priority']; unset($value['priority']); } - + if (array_key_exists('color', $value)) { $this->_usedProperties['color'] = true; $this->color = $value['color']; unset($value['color']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -71,7 +68,7 @@ public function toArray(): array if (isset($this->_usedProperties['color'])) { $output['color'] = $this->color; } - + return $output; } 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 275dca34da3af..563ec25dcdaf2 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 @@ -2,11 +2,9 @@ namespace Symfony\Config\AddToList\Messenger; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -14,7 +12,7 @@ class RoutingConfig { private $senders; private $_usedProperties = []; - + /** * @param ParamConfigurator|list $value * @return $this @@ -23,31 +21,30 @@ public function senders($value): self { $this->_usedProperties['senders'] = true; $this->senders = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('senders', $value)) { $this->_usedProperties['senders'] = true; $this->senders = $value['senders']; unset($value['senders']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; if (isset($this->_usedProperties['senders'])) { $output['senders'] = $this->senders; } - + return $output; } 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 85b593a1b05f1..bc8625d9fb0c1 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 @@ -7,7 +7,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -16,48 +15,45 @@ 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) { - return $this->routing[$message_class]; + $this->routing[$message_class] = new \Symfony\Config\AddToList\Messenger\RoutingConfig($value); + } elseif (1 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "routing()" has already been initialized. You cannot pass values the second time you call routing().'); } - - throw new InvalidConfigurationException('The node created by "routing()" has already been initialized. You cannot pass values the second time you call routing().'); + + return $this->routing[$message_class]; } - + 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 (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 (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']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -67,7 +63,7 @@ public function toArray(): array if (isset($this->_usedProperties['receiving'])) { $output['receiving'] = array_map(function ($v) { return $v->toArray(); }, $this->receiving); } - + return $output; } 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 79f041cea6da0..25813dade63a8 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 @@ -2,11 +2,9 @@ namespace Symfony\Config\AddToList; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -15,7 +13,7 @@ class TranslatorConfig private $fallbacks; private $sources; private $_usedProperties = []; - + /** * @param ParamConfigurator|list $value * @return $this @@ -24,10 +22,10 @@ public function fallbacks($value): self { $this->_usedProperties['fallbacks'] = true; $this->fallbacks = $value; - + return $this; } - + /** * @param ParamConfigurator|mixed $value * @return $this @@ -36,30 +34,29 @@ public function source(string $source_class, $value): self { $this->_usedProperties['sources'] = true; $this->sources[$source_class] = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('fallbacks', $value)) { $this->_usedProperties['fallbacks'] = true; $this->fallbacks = $value['fallbacks']; unset($value['fallbacks']); } - + if (array_key_exists('sources', $value)) { $this->_usedProperties['sources'] = true; $this->sources = $value['sources']; unset($value['sources']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -69,7 +66,7 @@ public function toArray(): array if (isset($this->_usedProperties['sources'])) { $output['sources'] = $this->sources; } - + return $output; } 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 e6f0c262b88db..a8b0adb28b5f2 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 @@ -7,7 +7,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -16,56 +15,55 @@ class AddToListConfig implements \Symfony\Component\Config\Builder\ConfigBuilder 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) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "translator()" has already been initialized. You cannot pass values the second time you call translator().'); } - + return $this->translator; } - + 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) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "messenger()" has already been initialized. You cannot pass values the second time you call messenger().'); } - + return $this->messenger; } - + public function getExtensionAlias(): string { return 'add_to_list'; } - + public function __construct(array $value = []) { - if (array_key_exists('translator', $value)) { $this->_usedProperties['translator'] = true; $this->translator = new \Symfony\Config\AddToList\TranslatorConfig($value['translator']); unset($value['translator']); } - + if (array_key_exists('messenger', $value)) { $this->_usedProperties['messenger'] = true; $this->messenger = new \Symfony\Config\AddToList\MessengerConfig($value['messenger']); unset($value['messenger']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -75,7 +73,7 @@ public function toArray(): array if (isset($this->_usedProperties['messenger'])) { $output['messenger'] = $this->messenger->toArray(); } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.config.php index 45069e7490c22..598255fec6bf6 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.config.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Symfony\Config\ArrayExtraKeysConfig; return static function (ArrayExtraKeysConfig $config) { 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 d2fdc1ef5c8e4..ff0bdbd686cb7 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.output.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'foo' => [ 'baz' => 'foo_baz', diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.php index 751fe5c2934cc..96c515e55b46d 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayExtraKeys.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; 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 256454f164bbf..bb3c6f568607b 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 @@ -2,10 +2,8 @@ namespace Symfony\Config\ArrayExtraKeys; - use Symfony\Component\Config\Loader\ParamConfigurator; - /** * This class is automatically generated to help in creating a config. */ @@ -15,7 +13,7 @@ class BarConfig private $grault; private $_usedProperties = []; private $_extraKeys; - + /** * @default null * @param ParamConfigurator|mixed $value @@ -25,10 +23,10 @@ public function corge($value): self { $this->_usedProperties['corge'] = true; $this->corge = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -38,29 +36,28 @@ public function grault($value): self { $this->_usedProperties['grault'] = true; $this->grault = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('corge', $value)) { $this->_usedProperties['corge'] = true; $this->corge = $value['corge']; unset($value['corge']); } - + if (array_key_exists('grault', $value)) { $this->_usedProperties['grault'] = true; $this->grault = $value['grault']; unset($value['grault']); } - + $this->_extraKeys = $value; - + } - + public function toArray(): array { $output = []; @@ -70,10 +67,10 @@ public function toArray(): array if (isset($this->_usedProperties['grault'])) { $output['grault'] = $this->grault; } - + return $output + $this->_extraKeys; } - + /** * @param ParamConfigurator|mixed $value * @return $this @@ -81,7 +78,7 @@ public function toArray(): array public function set(string $key, $value): self { $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 d64633eab9c66..e198dac797e05 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 @@ -2,31 +2,28 @@ namespace Symfony\Config\ArrayExtraKeys; - use Symfony\Component\Config\Loader\ParamConfigurator; - /** * This class is automatically generated to help in creating a config. */ class BazConfig { private $_extraKeys; - + public function __construct(array $value = []) { - $this->_extraKeys = $value; - + } - + public function toArray(): array { $output = []; - + return $output + $this->_extraKeys; } - + /** * @param ParamConfigurator|mixed $value * @return $this @@ -34,7 +31,7 @@ public function toArray(): array public function set(string $key, $value): self { $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 c8f713341eda3..1204c3a06f74a 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 @@ -2,10 +2,8 @@ namespace Symfony\Config\ArrayExtraKeys; - use Symfony\Component\Config\Loader\ParamConfigurator; - /** * This class is automatically generated to help in creating a config. */ @@ -15,7 +13,7 @@ class FooConfig private $qux; private $_usedProperties = []; private $_extraKeys; - + /** * @default null * @param ParamConfigurator|mixed $value @@ -25,10 +23,10 @@ public function baz($value): self { $this->_usedProperties['baz'] = true; $this->baz = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -38,29 +36,28 @@ public function qux($value): self { $this->_usedProperties['qux'] = true; $this->qux = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('baz', $value)) { $this->_usedProperties['baz'] = true; $this->baz = $value['baz']; unset($value['baz']); } - + if (array_key_exists('qux', $value)) { $this->_usedProperties['qux'] = true; $this->qux = $value['qux']; unset($value['qux']); } - + $this->_extraKeys = $value; - + } - + public function toArray(): array { $output = []; @@ -70,10 +67,10 @@ public function toArray(): array if (isset($this->_usedProperties['qux'])) { $output['qux'] = $this->qux; } - + return $output + $this->_extraKeys; } - + /** * @param ParamConfigurator|mixed $value * @return $this @@ -81,7 +78,7 @@ public function toArray(): array public function set(string $key, $value): self { $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 3d8adb7095b33..2d7628f038736 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 @@ -8,7 +8,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -18,69 +17,68 @@ class ArrayExtraKeysConfig implements \Symfony\Component\Config\Builder\ConfigBu 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) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "foo()" has already been initialized. You cannot pass values the second time you call foo().'); } - + return $this->foo; } - + 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) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "baz()" has already been initialized. You cannot pass values the second time you call baz().'); } - + return $this->baz; } - + public function getExtensionAlias(): string { return 'array_extra_keys'; } - + public function __construct(array $value = []) { - if (array_key_exists('foo', $value)) { $this->_usedProperties['foo'] = true; $this->foo = new \Symfony\Config\ArrayExtraKeys\FooConfig($value['foo']); unset($value['foo']); } - + 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 (array_key_exists('baz', $value)) { $this->_usedProperties['baz'] = true; $this->baz = new \Symfony\Config\ArrayExtraKeys\BazConfig($value['baz']); unset($value['baz']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -93,7 +91,7 @@ public function toArray(): array if (isset($this->_usedProperties['baz'])) { $output['baz'] = $this->baz->toArray(); } - + return $output; } 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 4b86755c91a5b..430258ac382fa 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.config.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Symfony\Config\NodeInitialValuesConfig; return static function (NodeInitialValuesConfig $config) { 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 7fe70f9645b9e..c4ad8affe2144 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.output.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'some_clever_name' => [ 'first' => 'bar', diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.php index c290cf9730670..153af57be9b5b 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/NodeInitialValues.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; 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 3acc0247ac726..5fa9c2b426464 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 @@ -2,11 +2,9 @@ namespace Symfony\Config\NodeInitialValues\Messenger; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -16,7 +14,7 @@ class TransportsConfig private $serializer; private $options; private $_usedProperties = []; - + /** * @default null * @param ParamConfigurator|mixed $value @@ -26,10 +24,10 @@ public function dsn($value): self { $this->_usedProperties['dsn'] = true; $this->dsn = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -39,10 +37,10 @@ public function serializer($value): self { $this->_usedProperties['serializer'] = true; $this->serializer = $value; - + return $this; } - + /** * @param ParamConfigurator|list $value * @return $this @@ -51,36 +49,35 @@ public function options($value): self { $this->_usedProperties['options'] = true; $this->options = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('dsn', $value)) { $this->_usedProperties['dsn'] = true; $this->dsn = $value['dsn']; unset($value['dsn']); } - + if (array_key_exists('serializer', $value)) { $this->_usedProperties['serializer'] = true; $this->serializer = $value['serializer']; unset($value['serializer']); } - + if (array_key_exists('options', $value)) { $this->_usedProperties['options'] = true; $this->options = $value['options']; unset($value['options']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -93,7 +90,7 @@ public function toArray(): array if (isset($this->_usedProperties['options'])) { $output['options'] = $this->options; } - + return $output; } 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 12ff61109cae7..d174c8932b4f8 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 @@ -6,7 +6,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -14,42 +13,39 @@ 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); + $this->transports[$name] = new \Symfony\Config\NodeInitialValues\Messenger\TransportsConfig($value); + } elseif (1 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "transports()" has already been initialized. You cannot pass values the second time you call transports().'); } - if ([] === $value) { - return $this->transports[$name]; - } - - throw new InvalidConfigurationException('The node created by "transports()" has already been initialized. You cannot pass values the second time you call transports().'); + + return $this->transports[$name]; } - + public function __construct(array $value = []) { - 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']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; if (isset($this->_usedProperties['transports'])) { $output['transports'] = array_map(function ($v) { return $v->toArray(); }, $this->transports); } - + return $output; } 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 3ca87c25eec12..9629e95bfa443 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 @@ -2,11 +2,9 @@ namespace Symfony\Config\NodeInitialValues; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -16,7 +14,7 @@ class SomeCleverNameConfig private $second; private $third; private $_usedProperties = []; - + /** * @default null * @param ParamConfigurator|mixed $value @@ -26,10 +24,10 @@ public function first($value): self { $this->_usedProperties['first'] = true; $this->first = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -39,10 +37,10 @@ public function second($value): self { $this->_usedProperties['second'] = true; $this->second = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -52,36 +50,35 @@ public function third($value): self { $this->_usedProperties['third'] = true; $this->third = $value; - + return $this; } - + public function __construct(array $value = []) { - if (array_key_exists('first', $value)) { $this->_usedProperties['first'] = true; $this->first = $value['first']; unset($value['first']); } - + 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))); } } - + public function toArray(): array { $output = []; @@ -94,7 +91,7 @@ public function toArray(): array 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 1ba307fb491eb..d019ecf81bb76 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 @@ -7,7 +7,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -16,56 +15,55 @@ class NodeInitialValuesConfig implements \Symfony\Component\Config\Builder\Confi 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) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "someCleverName()" has already been initialized. You cannot pass values the second time you call someCleverName().'); } - + return $this->someCleverName; } - + 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) { + } elseif (0 < \func_num_args()) { throw new InvalidConfigurationException('The node created by "messenger()" has already been initialized. You cannot pass values the second time you call messenger().'); } - + return $this->messenger; } - + public function getExtensionAlias(): string { return 'node_initial_values'; } - + public function __construct(array $value = []) { - 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 (array_key_exists('messenger', $value)) { $this->_usedProperties['messenger'] = true; $this->messenger = new \Symfony\Config\NodeInitialValues\MessengerConfig($value['messenger']); unset($value['messenger']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -75,7 +73,7 @@ public function toArray(): array if (isset($this->_usedProperties['messenger'])) { $output['messenger'] = $this->messenger->toArray(); } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.config.php index 089252f32f341..8e6b5ae3f90d0 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.config.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\DependencyInjection\Loader\Configurator; use Symfony\Config\PlaceholdersConfig; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.output.php index ca27298c368e9..56a5af670807a 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.output.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'enabled' => '%env(bool:FOO_ENABLED)%', 'favorite_float' => '%eulers_number%', diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.php index 6735b5e955675..5d9c680daaced 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/Placeholders.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; 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 15fe9b492270d..6b5872c9f0254 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 @@ -2,11 +2,9 @@ namespace Symfony\Config; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -16,7 +14,7 @@ class PlaceholdersConfig implements \Symfony\Component\Config\Builder\ConfigBuil private $favoriteFloat; private $goodIntegers; private $_usedProperties = []; - + /** * @default false * @param ParamConfigurator|bool $value @@ -26,10 +24,10 @@ public function enabled($value): self { $this->_usedProperties['enabled'] = true; $this->enabled = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|float $value @@ -39,10 +37,10 @@ public function favoriteFloat($value): self { $this->_usedProperties['favoriteFloat'] = true; $this->favoriteFloat = $value; - + return $this; } - + /** * @param ParamConfigurator|list $value * @return $this @@ -51,41 +49,40 @@ public function goodIntegers($value): self { $this->_usedProperties['goodIntegers'] = true; $this->goodIntegers = $value; - + return $this; } - + public function getExtensionAlias(): string { return 'placeholders'; } - + public function __construct(array $value = []) { - if (array_key_exists('enabled', $value)) { $this->_usedProperties['enabled'] = true; $this->enabled = $value['enabled']; unset($value['enabled']); } - + if (array_key_exists('favorite_float', $value)) { $this->_usedProperties['favoriteFloat'] = true; $this->favoriteFloat = $value['favorite_float']; unset($value['favorite_float']); } - + if (array_key_exists('good_integers', $value)) { $this->_usedProperties['goodIntegers'] = true; $this->goodIntegers = $value['good_integers']; unset($value['good_integers']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; @@ -98,7 +95,7 @@ public function toArray(): array if (isset($this->_usedProperties['goodIntegers'])) { $output['good_integers'] = $this->goodIntegers; } - + return $output; } 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 b4498957057c4..fd4c0ce5f2cfa 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.config.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Symfony\Config\PrimitiveTypesConfig; return static function (PrimitiveTypesConfig $config) { 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 366fd5c19f4cb..867e387dbf3c2 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.output.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'boolean_node' => true, 'enum_node' => 'foo', diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.php index 3d36f72bff2db..6ffcf5a4ef533 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/PrimitiveTypes.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; 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 8a1be4e46a204..9c56f26d91cf9 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 @@ -2,11 +2,9 @@ namespace Symfony\Config; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -19,7 +17,7 @@ class PrimitiveTypesConfig implements \Symfony\Component\Config\Builder\ConfigBu private $scalarNode; private $scalarNodeWithDefault; private $_usedProperties = []; - + /** * @default null * @param ParamConfigurator|bool $value @@ -29,10 +27,10 @@ public function booleanNode($value): self { $this->_usedProperties['booleanNode'] = true; $this->booleanNode = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|'foo'|'bar'|'baz' $value @@ -42,10 +40,10 @@ public function enumNode($value): self { $this->_usedProperties['enumNode'] = true; $this->enumNode = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|float $value @@ -55,10 +53,10 @@ public function floatNode($value): self { $this->_usedProperties['floatNode'] = true; $this->floatNode = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|int $value @@ -68,10 +66,10 @@ public function integerNode($value): self { $this->_usedProperties['integerNode'] = true; $this->integerNode = $value; - + return $this; } - + /** * @default null * @param ParamConfigurator|mixed $value @@ -81,10 +79,10 @@ public function scalarNode($value): self { $this->_usedProperties['scalarNode'] = true; $this->scalarNode = $value; - + return $this; } - + /** * @default true * @param ParamConfigurator|mixed $value @@ -94,59 +92,58 @@ public function scalarNodeWithDefault($value): self { $this->_usedProperties['scalarNodeWithDefault'] = true; $this->scalarNodeWithDefault = $value; - + return $this; } - + public function getExtensionAlias(): string { return 'primitive_types'; } - + public function __construct(array $value = []) { - if (array_key_exists('boolean_node', $value)) { $this->_usedProperties['booleanNode'] = true; $this->booleanNode = $value['boolean_node']; unset($value['boolean_node']); } - + if (array_key_exists('enum_node', $value)) { $this->_usedProperties['enumNode'] = true; $this->enumNode = $value['enum_node']; unset($value['enum_node']); } - + if (array_key_exists('float_node', $value)) { $this->_usedProperties['floatNode'] = true; $this->floatNode = $value['float_node']; unset($value['float_node']); } - + if (array_key_exists('integer_node', $value)) { $this->_usedProperties['integerNode'] = true; $this->integerNode = $value['integer_node']; unset($value['integer_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))); } } - + public function toArray(): array { $output = []; @@ -168,7 +165,7 @@ public function toArray(): array if (isset($this->_usedProperties['scalarNodeWithDefault'])) { $output['scalar_node_with_default'] = $this->scalarNodeWithDefault; } - + return $output; } diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.config.php index e7553fc94f17b..d0c6d320709c2 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.config.php @@ -1,12 +1,31 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Symfony\Config\ScalarNormalizedTypesConfig; return static function (ScalarNormalizedTypesConfig $config) { $config ->simpleArray('foo') ->keyedArray('key', 'value') + ->object(true) ->listObject('bar') ->listObject('baz') ->listObject()->name('qux'); + + $config + ->keyedListObject('Foo\\Bar', true) + ->keyedListObject('Foo\\Baz')->settings(['one', 'two']); + + $config->nested([ + 'nested_object' => true, + 'nested_list_object' => ['one', 'two'], + ]); }; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.output.php index ae84a56709062..9dcf3a9f3d335 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.output.php @@ -1,13 +1,33 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'simple_array' => 'foo', 'keyed_array' => [ - 'key' => 'value' + 'key' => 'value', ], + 'object' => true, 'list_object' => [ 'bar', 'baz', ['name' => 'qux'], ], + 'keyed_list_object' => [ + 'Foo\\Bar' => true, + 'Foo\\Baz' => [ + 'settings' => ['one', 'two'], + ], + ], + 'nested' => [ + 'nested_object' => true, + 'nested_list_object' => ['one', 'two'], + ], ]; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.php index c33edeb4f062e..2c33797427eed 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; @@ -26,11 +35,23 @@ public function getConfigTreeBuilder(): TreeBuilder ->prototype('scalar')->end() ->end() ->end() + ->arrayNode('object') + ->addDefaultsIfNotSet() + ->beforeNormalization() + ->ifTrue(function ($v) { return !\is_array($v); }) + ->then(function ($v) { return ['enabled' => $v]; }) + ->end() + ->children() + ->booleanNode('enabled')->defaultNull()->end() + ->scalarNode('date_format')->end() + ->booleanNode('remove_used_context_fields')->end() + ->end() + ->end() ->arrayNode('list_object') ->beforeNormalization() ->always() ->then(function ($values) { - //inspired by Workflow places + // inspired by Workflow places if (isset($values[0]) && \is_string($values[0])) { return array_map(function (string $value) { return ['name' => $value]; @@ -51,19 +72,65 @@ public function getConfigTreeBuilder(): TreeBuilder return array_values($values); }) + ->end() + ->isRequired() + ->requiresAtLeastOneElement() + ->prototype('array') + ->children() + ->scalarNode('name') + ->isRequired() + ->cannotBeEmpty() + ->end() + ->arrayNode('data') + ->normalizeKeys(false) + ->defaultValue([]) + ->prototype('variable')->end() + ->end() ->end() - ->isRequired() - ->requiresAtLeastOneElement() - ->prototype('array') + ->end() + ->end() + ->arrayNode('keyed_list_object') + ->useAttributeAsKey('class') + ->prototype('array') + ->beforeNormalization() + ->ifTrue(function ($v) { return !\is_array($v); }) + ->then(function ($v) { return ['enabled' => $v]; }) + ->end() + ->children() + ->booleanNode('enabled')->defaultTrue()->end() + ->arrayNode('settings') + ->prototype('scalar')->end() + ->end() + ->end() + ->end() + ->end() + ->arrayNode('nested') + ->children() + ->arrayNode('nested_object') + ->addDefaultsIfNotSet() + ->beforeNormalization() + ->ifTrue(function ($v) { return !\is_array($v); }) + ->then(function ($v) { return ['enabled' => $v]; }) + ->end() ->children() - ->scalarNode('name') - ->isRequired() - ->cannotBeEmpty() - ->end() - ->arrayNode('data') - ->normalizeKeys(false) - ->defaultValue([]) - ->prototype('variable') + ->booleanNode('enabled')->defaultNull()->end() + ->end() + ->end() + ->arrayNode('nested_list_object') + ->beforeNormalization() + ->ifTrue(function ($v) { return isset($v[0]) && \is_string($v[0]); }) + ->then(function ($values) { + return array_map(function (string $value) { + return ['name' => $value]; + }, $values); + }) + ->end() + ->prototype('array') + ->children() + ->scalarNode('name') + ->isRequired() + ->cannotBeEmpty() + ->end() ->end() ->end() ->end() diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/KeyedListObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/KeyedListObjectConfig.php new file mode 100644 index 0000000000000..b9f25b224bcc2 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/KeyedListObjectConfig.php @@ -0,0 +1,74 @@ +_usedProperties['enabled'] = true; + $this->enabled = $value; + + return $this; + } + + /** + * @param ParamConfigurator|list $value + * @return $this + */ + public function settings($value): self + { + $this->_usedProperties['settings'] = true; + $this->settings = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('enabled', $value)) { + $this->_usedProperties['enabled'] = true; + $this->enabled = $value['enabled']; + unset($value['enabled']); + } + + if (array_key_exists('settings', $value)) { + $this->_usedProperties['settings'] = true; + $this->settings = $value['settings']; + unset($value['settings']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['enabled'])) { + $output['enabled'] = $this->enabled; + } + if (isset($this->_usedProperties['settings'])) { + $output['settings'] = $this->settings; + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ListObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ListObjectConfig.php new file mode 100644 index 0000000000000..969f4685c507d --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ListObjectConfig.php @@ -0,0 +1,74 @@ +_usedProperties['name'] = true; + $this->name = $value; + + return $this; + } + + /** + * @param ParamConfigurator|list $value + * @return $this + */ + public function data($value): self + { + $this->_usedProperties['data'] = true; + $this->data = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('name', $value)) { + $this->_usedProperties['name'] = true; + $this->name = $value['name']; + unset($value['name']); + } + + if (array_key_exists('data', $value)) { + $this->_usedProperties['data'] = true; + $this->data = $value['data']; + unset($value['data']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['name'])) { + $output['name'] = $this->name; + } + if (isset($this->_usedProperties['data'])) { + $output['data'] = $this->data; + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedListObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedListObjectConfig.php new file mode 100644 index 0000000000000..0815c1faaa5e0 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedListObjectConfig.php @@ -0,0 +1,52 @@ +_usedProperties['name'] = true; + $this->name = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('name', $value)) { + $this->_usedProperties['name'] = true; + $this->name = $value['name']; + unset($value['name']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['name'])) { + $output['name'] = $this->name; + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedObjectConfig.php new file mode 100644 index 0000000000000..279652138872e --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedObjectConfig.php @@ -0,0 +1,52 @@ +_usedProperties['enabled'] = true; + $this->enabled = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('enabled', $value)) { + $this->_usedProperties['enabled'] = true; + $this->enabled = $value['enabled']; + unset($value['enabled']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['enabled'])) { + $output['enabled'] = $this->enabled; + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/NestedConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/NestedConfig.php new file mode 100644 index 0000000000000..5774fdbb83821 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/NestedConfig.php @@ -0,0 +1,88 @@ +_usedProperties['nestedObject'] = true; + $this->nestedObject = $value; + + return $this; + } + + if (!$this->nestedObject instanceof \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig) { + $this->_usedProperties['nestedObject'] = true; + $this->nestedObject = new \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "nestedObject()" has already been initialized. You cannot pass values the second time you call nestedObject().'); + } + + return $this->nestedObject; + } + + /** + * @return \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig|$this + */ + public function nestedListObject($value = []) + { + $this->_usedProperties['nestedListObject'] = true; + if (!\is_array($value)) { + $this->nestedListObject[] = $value; + + return $this; + } + + return $this->nestedListObject[] = new \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig($value); + } + + public function __construct(array $value = []) + { + if (array_key_exists('nested_object', $value)) { + $this->_usedProperties['nestedObject'] = true; + $this->nestedObject = \is_array($value['nested_object']) ? new \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig($value['nested_object']) : $value['nested_object']; + unset($value['nested_object']); + } + + if (array_key_exists('nested_list_object', $value)) { + $this->_usedProperties['nestedListObject'] = true; + $this->nestedListObject = array_map(function ($v) { return \is_array($v) ? new \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig($v) : $v; }, $value['nested_list_object']); + unset($value['nested_list_object']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['nestedObject'])) { + $output['nested_object'] = $this->nestedObject instanceof \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig ? $this->nestedObject->toArray() : $this->nestedObject; + } + if (isset($this->_usedProperties['nestedListObject'])) { + $output['nested_list_object'] = array_map(function ($v) { return $v instanceof \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig ? $v->toArray() : $v; }, $this->nestedListObject); + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ObjectConfig.php new file mode 100644 index 0000000000000..74d0b6ee9bb3d --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ObjectConfig.php @@ -0,0 +1,98 @@ +_usedProperties['enabled'] = true; + $this->enabled = $value; + + return $this; + } + + /** + * @default null + * @param ParamConfigurator|mixed $value + * @return $this + */ + public function dateFormat($value): self + { + $this->_usedProperties['dateFormat'] = true; + $this->dateFormat = $value; + + return $this; + } + + /** + * @default null + * @param ParamConfigurator|bool $value + * @return $this + */ + public function removeUsedContextFields($value): self + { + $this->_usedProperties['removeUsedContextFields'] = true; + $this->removeUsedContextFields = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('enabled', $value)) { + $this->_usedProperties['enabled'] = true; + $this->enabled = $value['enabled']; + unset($value['enabled']); + } + + if (array_key_exists('date_format', $value)) { + $this->_usedProperties['dateFormat'] = true; + $this->dateFormat = $value['date_format']; + unset($value['date_format']); + } + + if (array_key_exists('remove_used_context_fields', $value)) { + $this->_usedProperties['removeUsedContextFields'] = true; + $this->removeUsedContextFields = $value['remove_used_context_fields']; + unset($value['remove_used_context_fields']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['enabled'])) { + $output['enabled'] = $this->enabled; + } + if (isset($this->_usedProperties['dateFormat'])) { + $output['date_format'] = $this->dateFormat; + } + if (isset($this->_usedProperties['removeUsedContextFields'])) { + $output['remove_used_context_fields'] = $this->removeUsedContextFields; + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypesConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypesConfig.php new file mode 100644 index 0000000000000..5ba2f1112ba10 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypesConfig.php @@ -0,0 +1,194 @@ + $value + * @return $this + */ + public function simpleArray($value): self + { + $this->_usedProperties['simpleArray'] = true; + $this->simpleArray = $value; + + return $this; + } + + /** + * @param ParamConfigurator|array $value + * @return $this + */ + public function keyedArray(string $name, $value): self + { + $this->_usedProperties['keyedArray'] = true; + $this->keyedArray[$name] = $value; + + return $this; + } + + /** + * @return \Symfony\Config\ScalarNormalizedTypes\ObjectConfig|$this + */ + public function object($value = []) + { + if (!\is_array($value)) { + $this->_usedProperties['object'] = true; + $this->object = $value; + + return $this; + } + + if (!$this->object instanceof \Symfony\Config\ScalarNormalizedTypes\ObjectConfig) { + $this->_usedProperties['object'] = true; + $this->object = new \Symfony\Config\ScalarNormalizedTypes\ObjectConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "object()" has already been initialized. You cannot pass values the second time you call object().'); + } + + return $this->object; + } + + /** + * @return \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig|$this + */ + public function listObject($value = []) + { + $this->_usedProperties['listObject'] = true; + if (!\is_array($value)) { + $this->listObject[] = $value; + + return $this; + } + + return $this->listObject[] = new \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig($value); + } + + /** + * @return \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig|$this + */ + public function keyedListObject(string $class, $value = []) + { + if (!\is_array($value)) { + $this->_usedProperties['keyedListObject'] = true; + $this->keyedListObject[$class] = $value; + + return $this; + } + + if (!isset($this->keyedListObject[$class]) || !$this->keyedListObject[$class] instanceof \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig) { + $this->_usedProperties['keyedListObject'] = true; + $this->keyedListObject[$class] = new \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig($value); + } elseif (1 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "keyedListObject()" has already been initialized. You cannot pass values the second time you call keyedListObject().'); + } + + return $this->keyedListObject[$class]; + } + + public function nested(array $value = []): \Symfony\Config\ScalarNormalizedTypes\NestedConfig + { + if (null === $this->nested) { + $this->_usedProperties['nested'] = true; + $this->nested = new \Symfony\Config\ScalarNormalizedTypes\NestedConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "nested()" has already been initialized. You cannot pass values the second time you call nested().'); + } + + return $this->nested; + } + + public function getExtensionAlias(): string + { + return 'scalar_normalized_types'; + } + + public function __construct(array $value = []) + { + if (array_key_exists('simple_array', $value)) { + $this->_usedProperties['simpleArray'] = true; + $this->simpleArray = $value['simple_array']; + unset($value['simple_array']); + } + + if (array_key_exists('keyed_array', $value)) { + $this->_usedProperties['keyedArray'] = true; + $this->keyedArray = $value['keyed_array']; + unset($value['keyed_array']); + } + + if (array_key_exists('object', $value)) { + $this->_usedProperties['object'] = true; + $this->object = \is_array($value['object']) ? new \Symfony\Config\ScalarNormalizedTypes\ObjectConfig($value['object']) : $value['object']; + unset($value['object']); + } + + if (array_key_exists('list_object', $value)) { + $this->_usedProperties['listObject'] = true; + $this->listObject = array_map(function ($v) { return \is_array($v) ? new \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig($v) : $v; }, $value['list_object']); + unset($value['list_object']); + } + + if (array_key_exists('keyed_list_object', $value)) { + $this->_usedProperties['keyedListObject'] = true; + $this->keyedListObject = array_map(function ($v) { return \is_array($v) ? new \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig($v) : $v; }, $value['keyed_list_object']); + unset($value['keyed_list_object']); + } + + if (array_key_exists('nested', $value)) { + $this->_usedProperties['nested'] = true; + $this->nested = new \Symfony\Config\ScalarNormalizedTypes\NestedConfig($value['nested']); + unset($value['nested']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['simpleArray'])) { + $output['simple_array'] = $this->simpleArray; + } + if (isset($this->_usedProperties['keyedArray'])) { + $output['keyed_array'] = $this->keyedArray; + } + if (isset($this->_usedProperties['object'])) { + $output['object'] = $this->object instanceof \Symfony\Config\ScalarNormalizedTypes\ObjectConfig ? $this->object->toArray() : $this->object; + } + if (isset($this->_usedProperties['listObject'])) { + $output['list_object'] = array_map(function ($v) { return $v instanceof \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig ? $v->toArray() : $v; }, $this->listObject); + } + if (isset($this->_usedProperties['keyedListObject'])) { + $output['keyed_list_object'] = array_map(function ($v) { return $v instanceof \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig ? $v->toArray() : $v; }, $this->keyedListObject); + } + if (isset($this->_usedProperties['nested'])) { + $output['nested'] = $this->nested->toArray(); + } + + return $output; + } + +} diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.config.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.config.php index 10b70bf6d26f9..ed65c1f2c36cb 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.config.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.config.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Symfony\Config\VariableTypeConfig; return static function (VariableTypeConfig $config) { diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.output.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.output.php index 87c38a584a28a..71ef3f426a98a 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.output.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.output.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + return [ 'any_value' => 'foobar', ]; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.php index c3fa62cfd9e49..11a8bea6f8674 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/VariableType.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Config\Tests\Builder\Fixtures; use Symfony\Component\Config\Definition\Builder\TreeBuilder; 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 a36bf5f31c966..078226d25946f 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 @@ -2,11 +2,9 @@ namespace Symfony\Config; - use Symfony\Component\Config\Loader\ParamConfigurator; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; - /** * This class is automatically generated to help in creating a config. */ @@ -14,7 +12,7 @@ class VariableTypeConfig implements \Symfony\Component\Config\Builder\ConfigBuil { private $anyValue; private $_usedProperties = []; - + /** * @default null * @param ParamConfigurator|mixed $value @@ -24,36 +22,35 @@ public function anyValue($value): self { $this->_usedProperties['anyValue'] = true; $this->anyValue = $value; - + return $this; } - + public function getExtensionAlias(): string { return 'variable_type'; } - + public function __construct(array $value = []) { - if (array_key_exists('any_value', $value)) { $this->_usedProperties['anyValue'] = true; $this->anyValue = $value['any_value']; unset($value['any_value']); } - + if ([] !== $value) { throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); } } - + public function toArray(): array { $output = []; if (isset($this->_usedProperties['anyValue'])) { $output['any_value'] = $this->anyValue; } - + return $output; } From d8f84c736687ed0762758d81e6a6d0dff09382a7 Mon Sep 17 00:00:00 2001 From: Peter Potrowl Date: Wed, 4 May 2022 14:44:46 +0200 Subject: [PATCH 12/48] [HttpFoundation] [Session] Overwrite invalid session id --- .../Session/Storage/NativeSessionStorage.php | 6 ++++++ .../Tests/Session/Storage/NativeSessionStorageTest.php | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index 916961f5eed5c..76ebfa08a482d 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -152,6 +152,12 @@ public function start() throw new \RuntimeException(sprintf('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line)); } + $sessionId = $_COOKIE[session_name()] ?? null; + if ($sessionId && !preg_match('/^[a-zA-Z0-9,-]{22,}$/', $sessionId)) { + // the session ID in the header is invalid, create a new one + session_id(session_create_id()); + } + // ok to try and start the session if (!session_start()) { throw new \RuntimeException('Failed to start the session.'); diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php index c9aa9a27b527f..776da2adc27f1 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php @@ -293,4 +293,13 @@ public function testGetBagsOnceSessionStartedIsIgnored() $this->assertEquals($storage->getBag('flashes'), $bag); } + + public function testRegenerateInvalidSessionId() + { + $_COOKIE[session_name()] = '&~['; + $started = (new NativeSessionStorage())->start(); + + $this->assertTrue($started); + $this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id()); + } } From 43ff6a7b07e5cac30f59e5fa0a826b93bba1c19a Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Tue, 17 May 2022 13:19:39 +0200 Subject: [PATCH 13/48] [HtmlSanitizer] Fix default config service ID --- .../Bundle/FrameworkBundle/Resources/config/html_sanitizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/html_sanitizer.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/html_sanitizer.php index ba87eda1a3357..19e1a2175cdb1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/html_sanitizer.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/html_sanitizer.php @@ -21,7 +21,7 @@ ->call('allowSafeElements') ->set('html_sanitizer.sanitizer.default', HtmlSanitizer::class) - ->args([service('html_sanitizer.config')]) + ->args([service('html_sanitizer.config.default')]) ->tag('html_sanitizer', ['name' => 'default']) ->alias('html_sanitizer', 'html_sanitizer.sanitizer.default') From 9d38089d6ddadca4da178b59df8ab134f135e060 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Tue, 17 May 2022 14:08:13 +0200 Subject: [PATCH 14/48] [Config] Fix PHP Configuration type hints & tests --- .../Config/Builder/ConfigBuilderGenerator.php | 38 ++++++++++++++----- .../KeyedListObjectConfig.php | 7 ++-- .../ListObjectConfig.php | 7 ++-- .../Nested/NestedListObjectConfig.php | 2 +- .../Nested/NestedObjectConfig.php | 2 +- .../ScalarNormalizedTypes/NestedConfig.php | 4 +- .../ScalarNormalizedTypes/ObjectConfig.php | 6 +-- .../Config/ScalarNormalizedTypesConfig.php | 14 +++---- 8 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php b/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php index 4a374c50b989f..397ce7e2fc0ae 100644 --- a/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php +++ b/src/Symfony/Component/Config/Builder/ConfigBuilderGenerator.php @@ -145,7 +145,7 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n /** * @return CLASS|$this */ -public function NAME($value = []) +public function NAME(mixed $value = []): CLASS|static { if (!\is_array($value)) { $this->_usedProperties[\'PROPERTY\'] = true; @@ -198,7 +198,11 @@ public function NAME(mixed $valueDEFAULT): static return $this; }'; - $class->addMethod($node->getName(), $body, ['PROPERTY' => $property->getName(), 'COMMENT' => $comment, 'DEFAULT' => $node->hasDefaultValue() ? ' = '.var_export($node->getDefaultValue(), true) : '']); + $class->addMethod($node->getName(), $body, [ + 'PROPERTY' => $property->getName(), + 'COMMENT' => $comment, + 'DEFAULT' => $node->hasDefaultValue() ? ' = '.var_export($node->getDefaultValue(), true) : '', + ]); } private function handlePrototypedArrayNode(PrototypedArrayNode $node, ClassBuilder $class, string $namespace): void @@ -206,6 +210,7 @@ private function handlePrototypedArrayNode(PrototypedArrayNode $node, ClassBuild $name = $this->getSingularName($node); $prototype = $node->getPrototype(); $methodName = $name; + $hasNormalizationClosures = $this->hasNormalizationClosures($node) || $this->hasNormalizationClosures($prototype); $parameterType = $this->getParameterType($prototype); if (null !== $parameterType || $prototype instanceof ScalarNode) { @@ -215,11 +220,11 @@ private function handlePrototypedArrayNode(PrototypedArrayNode $node, ClassBuild // This is an array of values; don't use singular name $body = ' /** - * @param ParamConfigurator|list $value + * @param PHPDOC_TYPE $value * * @return $this */ -public function NAME(ParamConfigurator|array $value): static +public function NAME(TYPE $value): static { $this->_usedProperties[\'PROPERTY\'] = true; $this->PROPERTY = $value; @@ -227,7 +232,11 @@ public function NAME(ParamConfigurator|array $value): static return $this; }'; - $class->addMethod($node->getName(), $body, ['PROPERTY' => $property->getName(), 'TYPE' => '' === $parameterType ? 'mixed' : $parameterType]); + $class->addMethod($node->getName(), $body, [ + 'PROPERTY' => $property->getName(), + 'TYPE' => $hasNormalizationClosures ? 'mixed' : 'ParamConfigurator|array', + 'PHPDOC_TYPE' => $hasNormalizationClosures ? 'mixed' : sprintf('ParamConfigurator|list', '' === $parameterType ? 'mixed' : $parameterType), + ]); } else { $body = ' /** @@ -241,7 +250,12 @@ public function NAME(string $VAR, TYPE $VALUE): static return $this; }'; - $class->addMethod($methodName, $body, ['PROPERTY' => $property->getName(), 'TYPE' => '' === $parameterType ? 'mixed' : 'ParamConfigurator|'.$parameterType, 'VAR' => '' === $key ? 'key' : $key, 'VALUE' => 'value' === $key ? 'data' : 'value']); + $class->addMethod($methodName, $body, [ + 'PROPERTY' => $property->getName(), + 'TYPE' => $hasNormalizationClosures || '' === $parameterType ? 'mixed' : 'ParamConfigurator|'.$parameterType, + 'VAR' => '' === $key ? 'key' : $key, + 'VALUE' => 'value' === $key ? 'data' : 'value', + ]); } return; @@ -254,7 +268,6 @@ public function NAME(string $VAR, TYPE $VALUE): static $class->addRequire($childClass); $this->classes[] = $childClass; - $hasNormalizationClosures = $this->hasNormalizationClosures($node) || $this->hasNormalizationClosures($prototype); $property = $class->addProperty( $node->getName(), $this->getType($childClass->getFqcn().'[]', $hasNormalizationClosures) @@ -265,7 +278,7 @@ public function NAME(string $VAR, TYPE $VALUE): static /** * @return CLASS|$this */ -public function NAME($value = []) +public function NAME(mixed $value = []): CLASS|static { $this->_usedProperties[\'PROPERTY\'] = true; if (!\is_array($value)) { @@ -288,7 +301,7 @@ public function NAME(array $value = []): CLASS /** * @return CLASS|$this */ -public function NAME(string $VAR, $VALUE = []) +public function NAME(string $VAR, mixed $VALUE = []): CLASS|static { if (!\is_array($VALUE)) { $this->_usedProperties[\'PROPERTY\'] = true; @@ -318,7 +331,12 @@ public function NAME(string $VAR, array $VALUE = []): CLASS return $this->PROPERTY[$VAR]; }'; $class->addUse(InvalidConfigurationException::class); - $class->addMethod($methodName, $body, ['PROPERTY' => $property->getName(), 'CLASS' => $childClass->getFqcn(), 'VAR' => '' === $key ? 'key' : $key, 'VALUE' => 'value' === $key ? 'data' : 'value']); + $class->addMethod($methodName, $body, [ + 'PROPERTY' => $property->getName(), + 'CLASS' => $childClass->getFqcn(), + 'VAR' => '' === $key ? 'key' : $key, + 'VALUE' => 'value' === $key ? 'data' : 'value', + ]); } $this->buildNode($prototype, $childClass, $namespace.'\\'.$childClass->getName()); diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/KeyedListObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/KeyedListObjectConfig.php index b9f25b224bcc2..4ca54c31574d0 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/KeyedListObjectConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/KeyedListObjectConfig.php @@ -19,7 +19,7 @@ class KeyedListObjectConfig * @param ParamConfigurator|bool $value * @return $this */ - public function enabled($value): self + public function enabled($value): static { $this->_usedProperties['enabled'] = true; $this->enabled = $value; @@ -28,10 +28,11 @@ public function enabled($value): self } /** - * @param ParamConfigurator|list $value + * @param ParamConfigurator|list $value + * * @return $this */ - public function settings($value): self + public function settings(ParamConfigurator|array $value): static { $this->_usedProperties['settings'] = true; $this->settings = $value; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ListObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ListObjectConfig.php index 969f4685c507d..47217f41418bb 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ListObjectConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ListObjectConfig.php @@ -19,7 +19,7 @@ class ListObjectConfig * @param ParamConfigurator|mixed $value * @return $this */ - public function name($value): self + public function name($value): static { $this->_usedProperties['name'] = true; $this->name = $value; @@ -28,10 +28,11 @@ public function name($value): self } /** - * @param ParamConfigurator|list $value + * @param ParamConfigurator|list $value + * * @return $this */ - public function data($value): self + public function data(ParamConfigurator|array $value): static { $this->_usedProperties['data'] = true; $this->data = $value; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedListObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedListObjectConfig.php index 0815c1faaa5e0..52ebc9b09700a 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedListObjectConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedListObjectConfig.php @@ -18,7 +18,7 @@ class NestedListObjectConfig * @param ParamConfigurator|mixed $value * @return $this */ - public function name($value): self + public function name($value): static { $this->_usedProperties['name'] = true; $this->name = $value; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedObjectConfig.php index 279652138872e..00d4d72620b3e 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedObjectConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/Nested/NestedObjectConfig.php @@ -18,7 +18,7 @@ class NestedObjectConfig * @param ParamConfigurator|bool $value * @return $this */ - public function enabled($value): self + public function enabled($value): static { $this->_usedProperties['enabled'] = true; $this->enabled = $value; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/NestedConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/NestedConfig.php index 5774fdbb83821..fcad2cae332b0 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/NestedConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/NestedConfig.php @@ -19,7 +19,7 @@ class NestedConfig /** * @return \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig|$this */ - public function nestedObject($value = []) + public function nestedObject(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig|static { if (!\is_array($value)) { $this->_usedProperties['nestedObject'] = true; @@ -41,7 +41,7 @@ public function nestedObject($value = []) /** * @return \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig|$this */ - public function nestedListObject($value = []) + public function nestedListObject(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig|static { $this->_usedProperties['nestedListObject'] = true; if (!\is_array($value)) { diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ObjectConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ObjectConfig.php index 74d0b6ee9bb3d..00d1a573a9369 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ObjectConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/ObjectConfig.php @@ -20,7 +20,7 @@ class ObjectConfig * @param ParamConfigurator|bool $value * @return $this */ - public function enabled($value): self + public function enabled($value): static { $this->_usedProperties['enabled'] = true; $this->enabled = $value; @@ -33,7 +33,7 @@ public function enabled($value): self * @param ParamConfigurator|mixed $value * @return $this */ - public function dateFormat($value): self + public function dateFormat($value): static { $this->_usedProperties['dateFormat'] = true; $this->dateFormat = $value; @@ -46,7 +46,7 @@ public function dateFormat($value): self * @param ParamConfigurator|bool $value * @return $this */ - public function removeUsedContextFields($value): self + public function removeUsedContextFields($value): static { $this->_usedProperties['removeUsedContextFields'] = true; $this->removeUsedContextFields = $value; diff --git a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypesConfig.php b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypesConfig.php index 5ba2f1112ba10..fcd98f8d27ef5 100644 --- a/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypesConfig.php +++ b/src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypesConfig.php @@ -24,10 +24,11 @@ class ScalarNormalizedTypesConfig implements \Symfony\Component\Config\Builder\C private $_usedProperties = []; /** - * @param ParamConfigurator|list $value + * @param mixed $value + * * @return $this */ - public function simpleArray($value): self + public function simpleArray(mixed $value): static { $this->_usedProperties['simpleArray'] = true; $this->simpleArray = $value; @@ -36,10 +37,9 @@ public function simpleArray($value): self } /** - * @param ParamConfigurator|array $value * @return $this */ - public function keyedArray(string $name, $value): self + public function keyedArray(string $name, mixed $value): static { $this->_usedProperties['keyedArray'] = true; $this->keyedArray[$name] = $value; @@ -50,7 +50,7 @@ public function keyedArray(string $name, $value): self /** * @return \Symfony\Config\ScalarNormalizedTypes\ObjectConfig|$this */ - public function object($value = []) + public function object(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\ObjectConfig|static { if (!\is_array($value)) { $this->_usedProperties['object'] = true; @@ -72,7 +72,7 @@ public function object($value = []) /** * @return \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig|$this */ - public function listObject($value = []) + public function listObject(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig|static { $this->_usedProperties['listObject'] = true; if (!\is_array($value)) { @@ -87,7 +87,7 @@ public function listObject($value = []) /** * @return \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig|$this */ - public function keyedListObject(string $class, $value = []) + public function keyedListObject(string $class, mixed $value = []): \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig|static { if (!\is_array($value)) { $this->_usedProperties['keyedListObject'] = true; From 0f4a3cc2fcebe2ad667dd6649e77db5c144d85a2 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Tue, 17 May 2022 15:15:59 +0200 Subject: [PATCH 15/48] [HttpKernel] Fix missing null type in `ErrorListener::__construct()` --- .../Component/HttpKernel/EventListener/ErrorListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php b/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php index 8bac8afe268e9..6b44a85791dc7 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php @@ -35,7 +35,7 @@ class ErrorListener implements EventSubscriberInterface protected $debug; protected $exceptionsMapping; - public function __construct(string|object|array $controller, LoggerInterface $logger = null, bool $debug = false, array $exceptionsMapping = []) + public function __construct(string|object|array|null $controller, LoggerInterface $logger = null, bool $debug = false, array $exceptionsMapping = []) { $this->controller = $controller; $this->logger = $logger; From 54d442a8d8f1ed1aaa28f23902f67b86327e17f2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 17 May 2022 16:13:46 +0200 Subject: [PATCH 16/48] [HttpClient] Add missing HttpOptions::setMaxDuration() --- src/Symfony/Component/HttpClient/HttpOptions.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Symfony/Component/HttpClient/HttpOptions.php b/src/Symfony/Component/HttpClient/HttpOptions.php index 1638189f6439b..da55f9965f98c 100644 --- a/src/Symfony/Component/HttpClient/HttpOptions.php +++ b/src/Symfony/Component/HttpClient/HttpOptions.php @@ -197,6 +197,16 @@ public function setTimeout(float $timeout) return $this; } + /** + * @return $this + */ + public function setMaxDuration(float $maxDuration) + { + $this->options['max_duration'] = $maxDuration; + + return $this; + } + /** * @return $this */ From a3da68056b7b210160a3e3461116fe27b9916933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 17 May 2022 22:50:08 +0200 Subject: [PATCH 17/48] Complete negatable options --- .../Output/BashCompletionOutput.php | 3 ++ .../Tests/Command/CompleteCommandTest.php | 4 +- .../Output/BashCompletionOutputTest.php | 33 ++++++++++++ .../Output/CompletionOutputTestCase.php | 51 +++++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Component/Console/Tests/Completion/Output/BashCompletionOutputTest.php create mode 100644 src/Symfony/Component/Console/Tests/Completion/Output/CompletionOutputTestCase.php diff --git a/src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php b/src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php index 8d5ffa6b67d4b..c6f76eb8fbd40 100644 --- a/src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php +++ b/src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php @@ -24,6 +24,9 @@ public function write(CompletionSuggestions $suggestions, OutputInterface $outpu $values = $suggestions->getValueSuggestions(); foreach ($suggestions->getOptionSuggestions() as $option) { $values[] = '--'.$option->getName(); + if ($option->isNegatable()) { + $values[] = '--no-'.$option->getName(); + } } $output->writeln(implode("\n", $values)); } diff --git a/src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php b/src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php index f3ffe7b502dcb..642d5c69a58ac 100644 --- a/src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php @@ -119,9 +119,9 @@ public function testCompleteCommandInputDefinition(array $input, array $suggesti public function provideCompleteCommandInputDefinitionInputs() { - yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']]; + yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']]; yield 'custom' => [['bin/console', 'hello'], ['Fabien', 'Robin', 'Wouter']]; - yield 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']]; + yield 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']]; yield 'custom-aliased' => [['bin/console', 'ahoy'], ['Fabien', 'Robin', 'Wouter']]; } diff --git a/src/Symfony/Component/Console/Tests/Completion/Output/BashCompletionOutputTest.php b/src/Symfony/Component/Console/Tests/Completion/Output/BashCompletionOutputTest.php new file mode 100644 index 0000000000000..84ec56accbbfd --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Completion/Output/BashCompletionOutputTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Completion\Output; + +use Symfony\Component\Console\Completion\Output\BashCompletionOutput; +use Symfony\Component\Console\Completion\Output\CompletionOutputInterface; + +class BashCompletionOutputTest extends CompletionOutputTestCase +{ + public function getCompletionOutput(): CompletionOutputInterface + { + return new BashCompletionOutput(); + } + + public function getExpectedOptionsOutput(): string + { + return "--option1\n--negatable\n--no-negatable".\PHP_EOL; + } + + public function getExpectedValuesOutput(): string + { + return "Green\nRed\nYellow".\PHP_EOL; + } +} diff --git a/src/Symfony/Component/Console/Tests/Completion/Output/CompletionOutputTestCase.php b/src/Symfony/Component/Console/Tests/Completion/Output/CompletionOutputTestCase.php new file mode 100644 index 0000000000000..c4551e5b67b70 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Completion/Output/CompletionOutputTestCase.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Completion\Output; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Completion\CompletionSuggestions; +use Symfony\Component\Console\Completion\Output\CompletionOutputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\StreamOutput; + +abstract class CompletionOutputTestCase extends TestCase +{ + abstract public function getCompletionOutput(): CompletionOutputInterface; + + abstract public function getExpectedOptionsOutput(): string; + + abstract public function getExpectedValuesOutput(): string; + + public function testOptionsOutput() + { + $options = [ + new InputOption('option1', 'o', InputOption::VALUE_NONE), + new InputOption('negatable', null, InputOption::VALUE_NEGATABLE), + ]; + $suggestions = new CompletionSuggestions(); + $suggestions->suggestOptions($options); + $stream = fopen('php://memory', 'rw+'); + $this->getCompletionOutput()->write($suggestions, new StreamOutput($stream)); + fseek($stream, 0); + $this->assertEquals($this->getExpectedOptionsOutput(), stream_get_contents($stream)); + } + + public function testValuesOutput() + { + $suggestions = new CompletionSuggestions(); + $suggestions->suggestValues(['Green', 'Red', 'Yellow']); + $stream = fopen('php://memory', 'rw+'); + $this->getCompletionOutput()->write($suggestions, new StreamOutput($stream)); + fseek($stream, 0); + $this->assertEquals($this->getExpectedValuesOutput(), stream_get_contents($stream)); + } +} From 953f5059e672801ce5c752845afce22861e069ca Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 18 May 2022 09:59:32 +0200 Subject: [PATCH 18/48] [FrameworkBundle] Simplify registration of #[AsRoutingConditionService] --- .../DependencyInjection/FrameworkExtension.php | 5 ----- .../Routing/Attribute/AsRoutingConditionService.php | 9 ++++++--- src/Symfony/Bundle/FrameworkBundle/composer.json | 8 ++++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 07f15e9b28b52..37b6efc5cb245 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -27,7 +27,6 @@ use Symfony\Bridge\Twig\Extension\CsrfExtension; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader; -use Symfony\Bundle\FrameworkBundle\Routing\Attribute\AsRoutingConditionService; use Symfony\Bundle\FrameworkBundle\Routing\RouteLoaderInterface; use Symfony\Bundle\FullStack; use Symfony\Bundle\MercureBundle\MercureBundle; @@ -683,10 +682,6 @@ public function load(array $configs, ContainerBuilder $container) 'kernel.locale_aware', 'kernel.reset', ]); - - $container->registerAttributeForAutoconfiguration(AsRoutingConditionService::class, static function (ChildDefinition $definition, AsRoutingConditionService $attribute): void { - $definition->addTag('routing.condition_service', (array) $attribute); - }); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Attribute/AsRoutingConditionService.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Attribute/AsRoutingConditionService.php index 7467913e21c05..d1f1a5f34a654 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Attribute/AsRoutingConditionService.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/Attribute/AsRoutingConditionService.php @@ -11,6 +11,8 @@ namespace Symfony\Bundle\FrameworkBundle\Routing\Attribute; +use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; + /** * Service tag to autoconfigure routing condition services. * @@ -37,11 +39,12 @@ * } */ #[\Attribute(\Attribute::TARGET_CLASS)] -class AsRoutingConditionService +class AsRoutingConditionService extends AutoconfigureTag { public function __construct( - public ?string $alias = null, - public int $priority = 0, + string $alias = null, + int $priority = 0, ) { + parent::__construct('routing.condition_service', ['alias' => $alias, 'priority' => $priority]); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 5c7ed9028f7eb..1a301287d043d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -20,11 +20,11 @@ "composer-runtime-api": ">=2.1", "ext-xml": "*", "symfony/cache": "^5.4|^6.0", - "symfony/config": "^5.4|^6.0", - "symfony/dependency-injection": "^5.4.5|^6.0.5", + "symfony/config": "^6.1", + "symfony/dependency-injection": "^6.1", "symfony/deprecation-contracts": "^2.1|^3", + "symfony/error-handler": "^6.1", "symfony/event-dispatcher": "^5.4|^6.0", - "symfony/error-handler": "^5.4|^6.0", "symfony/http-foundation": "^5.4|^6.0", "symfony/http-kernel": "^6.1", "symfony/polyfill-mbstring": "~1.0", @@ -55,7 +55,7 @@ "symfony/rate-limiter": "^5.4|^6.0", "symfony/security-bundle": "^5.4|^6.0", "symfony/semaphore": "^5.4|^6.0", - "symfony/serializer": "^5.4|^6.0", + "symfony/serializer": "^6.1", "symfony/stopwatch": "^5.4|^6.0", "symfony/string": "^5.4|^6.0", "symfony/translation": "^5.4|^6.0", From c81d1165f270e2aa8bac7bc682a0ab76720b09f5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 17 May 2022 16:09:08 +0200 Subject: [PATCH 19/48] [HttpClient] Honor "max_duration" when replacing requests with async decorators --- .../HttpClient/Response/AmpResponse.php | 1 + .../HttpClient/Response/AsyncContext.php | 8 +++++- .../HttpClient/Response/AsyncResponse.php | 3 +++ .../HttpClient/Response/CurlResponse.php | 1 + .../HttpClient/Response/MockResponse.php | 2 ++ .../HttpClient/Response/NativeResponse.php | 1 + .../Tests/AsyncDecoratorTraitTest.php | 25 +++++++++++++++++++ 7 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpClient/Response/AmpResponse.php b/src/Symfony/Component/HttpClient/Response/AmpResponse.php index 9015a06d063a5..6d0ce6e33e01f 100644 --- a/src/Symfony/Component/HttpClient/Response/AmpResponse.php +++ b/src/Symfony/Component/HttpClient/Response/AmpResponse.php @@ -87,6 +87,7 @@ public function __construct(AmpClientState $multi, Request $request, array $opti $info['upload_content_length'] = -1.0; $info['download_content_length'] = -1.0; $info['user_data'] = $options['user_data']; + $info['max_duration'] = $options['max_duration']; $info['debug'] = ''; $onProgress = $options['on_progress'] ?? static function () {}; diff --git a/src/Symfony/Component/HttpClient/Response/AsyncContext.php b/src/Symfony/Component/HttpClient/Response/AsyncContext.php index 1af8dbee5ede3..2d95e11f507f1 100644 --- a/src/Symfony/Component/HttpClient/Response/AsyncContext.php +++ b/src/Symfony/Component/HttpClient/Response/AsyncContext.php @@ -13,6 +13,7 @@ use Symfony\Component\HttpClient\Chunk\DataChunk; use Symfony\Component\HttpClient\Chunk\LastChunk; +use Symfony\Component\HttpClient\Exception\TransportException; use Symfony\Contracts\HttpClient\ChunkInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\ResponseInterface; @@ -152,13 +153,18 @@ public function getResponse(): ResponseInterface */ public function replaceRequest(string $method, string $url, array $options = []): ResponseInterface { - $this->info['previous_info'][] = $this->response->getInfo(); + $this->info['previous_info'][] = $info = $this->response->getInfo(); if (null !== $onProgress = $options['on_progress'] ?? null) { $thisInfo = &$this->info; $options['on_progress'] = static function (int $dlNow, int $dlSize, array $info) use (&$thisInfo, $onProgress) { $onProgress($dlNow, $dlSize, $thisInfo + $info); }; } + if (0 < ($info['max_duration'] ?? 0) && 0 < ($info['total_time'] ?? 0)) { + if (0 >= $options['max_duration'] = $info['max_duration'] - $info['total_time']) { + throw new TransportException(sprintf('Max duration was reached for "%s".', $info['url'])); + } + } return $this->response = $this->client->request($method, $url, ['buffer' => false] + $options); } diff --git a/src/Symfony/Component/HttpClient/Response/AsyncResponse.php b/src/Symfony/Component/HttpClient/Response/AsyncResponse.php index c164fadb93ea9..80c9f7da370fa 100644 --- a/src/Symfony/Component/HttpClient/Response/AsyncResponse.php +++ b/src/Symfony/Component/HttpClient/Response/AsyncResponse.php @@ -85,6 +85,9 @@ public function __construct(HttpClientInterface $client, string $method, string if (\array_key_exists('user_data', $options)) { $this->info['user_data'] = $options['user_data']; } + if (\array_key_exists('max_duration', $options)) { + $this->info['max_duration'] = $options['max_duration']; + } } public function getStatusCode(): int diff --git a/src/Symfony/Component/HttpClient/Response/CurlResponse.php b/src/Symfony/Component/HttpClient/Response/CurlResponse.php index 5739392548c9d..c4ec5ce8d6130 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -65,6 +65,7 @@ public function __construct(CurlClientState $multi, $ch, array $options = null, $this->timeout = $options['timeout'] ?? null; $this->info['http_method'] = $method; $this->info['user_data'] = $options['user_data'] ?? null; + $this->info['max_duration'] = $options['max_duration'] ?? null; $this->info['start_time'] = $this->info['start_time'] ?? microtime(true); $info = &$this->info; $headers = &$this->headers; diff --git a/src/Symfony/Component/HttpClient/Response/MockResponse.php b/src/Symfony/Component/HttpClient/Response/MockResponse.php index 7177795d0acda..6420aa05de79a 100644 --- a/src/Symfony/Component/HttpClient/Response/MockResponse.php +++ b/src/Symfony/Component/HttpClient/Response/MockResponse.php @@ -140,6 +140,7 @@ public static function fromRequest(string $method, string $url, array $options, $response->info['http_method'] = $method; $response->info['http_code'] = 0; $response->info['user_data'] = $options['user_data'] ?? null; + $response->info['max_duration'] = $options['max_duration'] ?? null; $response->info['url'] = $url; if ($mock instanceof self) { @@ -285,6 +286,7 @@ private static function readResponse(self $response, array $options, ResponseInt $response->info = [ 'start_time' => $response->info['start_time'], 'user_data' => $response->info['user_data'], + 'max_duration' => $response->info['max_duration'], 'http_code' => $response->info['http_code'], ] + $info + $response->info; diff --git a/src/Symfony/Component/HttpClient/Response/NativeResponse.php b/src/Symfony/Component/HttpClient/Response/NativeResponse.php index c06237bec2915..c00e946f63508 100644 --- a/src/Symfony/Component/HttpClient/Response/NativeResponse.php +++ b/src/Symfony/Component/HttpClient/Response/NativeResponse.php @@ -59,6 +59,7 @@ public function __construct(NativeClientState $multi, $context, string $url, arr $this->buffer = fopen('php://temp', 'w+'); $info['user_data'] = $options['user_data']; + $info['max_duration'] = $options['max_duration']; ++$multi->responseCount; $this->initializer = static function (self $response) { diff --git a/src/Symfony/Component/HttpClient/Tests/AsyncDecoratorTraitTest.php b/src/Symfony/Component/HttpClient/Tests/AsyncDecoratorTraitTest.php index 0dfca6d4a2f97..199d2cf5d0b81 100644 --- a/src/Symfony/Component/HttpClient/Tests/AsyncDecoratorTraitTest.php +++ b/src/Symfony/Component/HttpClient/Tests/AsyncDecoratorTraitTest.php @@ -13,6 +13,7 @@ use Symfony\Component\HttpClient\AsyncDecoratorTrait; use Symfony\Component\HttpClient\DecoratorTrait; +use Symfony\Component\HttpClient\Exception\TransportException; use Symfony\Component\HttpClient\HttpClient; use Symfony\Component\HttpClient\Response\AsyncContext; use Symfony\Component\HttpClient\Response\AsyncResponse; @@ -339,4 +340,28 @@ public function request(string $method, string $url, array $options = []): Respo $this->expectExceptionMessage('Instance of "Symfony\Component\HttpClient\Response\NativeResponse" is already consumed and cannot be managed by "Symfony\Component\HttpClient\Response\AsyncResponse". A decorated client should not call any of the response\'s methods in its "request()" method.'); $response->getStatusCode(); } + + public function testMaxDuration() + { + $sawFirst = false; + $client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) use (&$sawFirst) { + try { + if (!$chunk->isFirst() || !$sawFirst) { + $sawFirst = $sawFirst || $chunk->isFirst(); + yield $chunk; + } + } catch (TransportExceptionInterface $e) { + $context->getResponse()->cancel(); + $context->replaceRequest('GET', 'http://localhost:8057/timeout-body', ['timeout' => 0.4]); + } + }); + + $response = $client->request('GET', 'http://localhost:8057/timeout-body', ['max_duration' => 0.75, 'timeout' => 0.4]); + + $this->assertSame(0.75, $response->getInfo('max_duration')); + + $this->expectException(TransportException::class); + $this->expectExceptionMessage('Max duration was reached for "http://localhost:8057/timeout-body".'); + $response->getContent(); + } } From 42fa0cbf36e4479d2b4702608086f5f87a4913af Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Thu, 19 May 2022 17:27:14 -0400 Subject: [PATCH 20/48] Fix dumping extension config without bundle --- .../Command/AbstractConfigCommand.php | 23 +++++------ .../Command/ConfigDebugCommand.php | 4 +- .../Command/ConfigDumpReferenceCommand.php | 5 ++- .../Functional/ConfigDebugCommandTest.php | 9 ++++ .../ConfigDumpReferenceCommandTest.php | 9 ++++ .../Extension/TestDumpExtension.php | 41 +++++++++++++++++++ .../Tests/Functional/app/AppKernel.php | 2 + 7 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php index 530cf95d2e488..a45c9c9c5fd8d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\StyleInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; /** @@ -59,7 +60,7 @@ protected function listBundles($output) /** * @return ExtensionInterface */ - protected function findExtension($name) + protected function findExtension($name, ContainerBuilder $container) { $bundles = $this->initializeBundles(); $minScore = \INF; @@ -79,20 +80,18 @@ protected function findExtension($name) $guess = $bundle->getName(); $minScore = $distance; } + } - $extension = $bundle->getContainerExtension(); - - if ($extension) { - if ($name === $extension->getAlias()) { - return $extension; - } + if ($container->hasExtension($name)) { + return $container->getExtension($name); + } - $distance = levenshtein($name, $extension->getAlias()); + foreach ($container->getExtensions() as $extension) { + $distance = levenshtein($name, $extension->getAlias()); - if ($distance < $minScore) { - $guess = $extension->getAlias(); - $minScore = $distance; - } + if ($distance < $minScore) { + $guess = $extension->getAlias(); + $minScore = $distance; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php index a0623f396127b..aa36b1fa80bdb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php @@ -79,9 +79,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - $extension = $this->findExtension($name); - $extensionAlias = $extension->getAlias(); $container = $this->compileContainer(); + $extension = $this->findExtension($name, $container); + $extensionAlias = $extension->getAlias(); $config = $container->resolveEnvPlaceholders( $container->getParameterBag()->resolveValue( diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php index 17690f7c99401..b104a1b806ca4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php @@ -89,9 +89,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - $extension = $this->findExtension($name); + $container = $this->getContainerBuilder(); + $extension = $this->findExtension($name, $container); - $configuration = $extension->getConfiguration([], $this->getContainerBuilder()); + $configuration = $extension->getConfiguration([], $container); $this->validateConfiguration($extension, $configuration); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php index 0df853997c59a..fbfa0be6e6c08 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php @@ -68,6 +68,15 @@ public function testDefaultParameterValueIsResolvedIfConfigIsExisting() $this->assertStringContainsString(sprintf("dsn: 'file:%s/profiler'", $kernelCacheDir), $tester->getDisplay()); } + public function testDumpExtensionConfigWithoutBundle() + { + $tester = $this->createCommandTester(); + $ret = $tester->execute(['name' => 'test_dump']); + + $this->assertSame(0, $ret, 'Returns 0 in case of success'); + $this->assertStringContainsString('enabled: true', $tester->getDisplay()); + } + public function testDumpUndefinedBundleOption() { $tester = $this->createCommandTester(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDumpReferenceCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDumpReferenceCommandTest.php index f4298ac9a851c..74c1889e2b99a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDumpReferenceCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDumpReferenceCommandTest.php @@ -40,6 +40,15 @@ public function testDumpBundleName() $this->assertStringContainsString(' custom:', $tester->getDisplay()); } + public function testDumpExtensionConfigWithoutBundle() + { + $tester = $this->createCommandTester(); + $ret = $tester->execute(['name' => 'test_dump']); + + $this->assertSame(0, $ret, 'Returns 0 in case of success'); + $this->assertStringContainsString('enabled: true', $tester->getDisplay()); + } + public function testDumpAtPath() { $tester = $this->createCommandTester(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php new file mode 100644 index 0000000000000..17738adf1b151 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Extension; + +use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; + +class TestDumpExtension extends Extension implements ConfigurationInterface +{ + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder('test_dump'); + $treeBuilder->getRootNode() + ->children() + ->booleanNode('enabled')->defaultTrue()->end() + ->end() + ; + + return $treeBuilder; + } + + public function load(array $configs, ContainerBuilder $container) + { + } + + public function getConfiguration(array $config, ContainerBuilder $container) + { + return $this; + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php index 94b9bfa012b3c..817c9360f4da3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\app; use Psr\Log\NullLogger; +use Symfony\Bundle\FrameworkBundle\Tests\Functional\Extension\TestDumpExtension; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -78,6 +79,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) protected function build(ContainerBuilder $container) { $container->register('logger', NullLogger::class); + $container->registerExtension(new TestDumpExtension()); } public function __sleep(): array From c15028f2d354d0bdc0f34f2d565da3323e6555a5 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 19 May 2022 13:09:40 +0200 Subject: [PATCH 21/48] [Filesystem] Safeguard (sym)link calls --- src/Symfony/Component/Filesystem/Filesystem.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 5c9bbd12b7107..fd1dbf39b2e06 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -318,6 +318,8 @@ private function isReadable(string $filename): bool */ public function symlink($originDir, $targetDir, $copyOnWindows = false) { + self::assertFunctionExists('symlink'); + if ('\\' === \DIRECTORY_SEPARATOR) { $originDir = strtr($originDir, '/', '\\'); $targetDir = strtr($targetDir, '/', '\\'); @@ -354,6 +356,8 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false) */ public function hardlink($originFile, $targetFiles) { + self::assertFunctionExists('link'); + if (!$this->exists($originFile)) { throw new FileNotFoundException(null, 0, null, $originFile); } @@ -737,13 +741,22 @@ private function getSchemeAndHierarchy(string $filename): array return 2 === \count($components) ? [$components[0], $components[1]] : [null, $components[0]]; } + private static function assertFunctionExists(string $func): void + { + if (!\function_exists($func)) { + throw new IOException(sprintf('Unable to perform filesystem operation because the "%s()" function has been disabled.', $func)); + } + } + /** * @param mixed ...$args * * @return mixed */ - private static function box(callable $func, ...$args) + private static function box(string $func, ...$args) { + self::assertFunctionExists($func); + self::$lastError = null; set_error_handler(__CLASS__.'::handleError'); try { From 65cbf18ea863740cd92dce772e02e074035cd653 Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Mon, 18 Apr 2022 23:46:24 +0200 Subject: [PATCH 22/48] [Form] Fix same choice loader with different choice values --- .../Form/ChoiceList/DoctrineChoiceLoader.php | 21 ++++++-------- .../ChoiceList/DoctrineChoiceLoaderTest.php | 3 +- .../Tests/Form/Type/EntityTypeTest.php | 28 ++++++++++++++++++ src/Symfony/Bridge/Doctrine/composer.json | 2 +- .../Loader/CallbackChoiceLoader.php | 12 ++++---- .../Tests/ChoiceList/LazyChoiceListTest.php | 10 +++---- .../Loader/CallbackChoiceLoaderTest.php | 13 +++++++-- .../Loader/IntlCallbackChoiceLoaderTest.php | 14 +++++++-- .../Extension/Core/Type/ChoiceTypeTest.php | 29 +++++++++++++++++++ 9 files changed, 100 insertions(+), 32 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php index c5ba42d471c35..0a5ea326eff0a 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php @@ -13,7 +13,6 @@ use Doctrine\Persistence\ObjectManager; use Symfony\Component\Form\ChoiceList\ArrayChoiceList; -use Symfony\Component\Form\ChoiceList\ChoiceListInterface; use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface; /** @@ -29,9 +28,9 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface private $objectLoader; /** - * @var ChoiceListInterface + * @var array|null */ - private $choiceList; + private $choices; /** * Creates a new choice loader. @@ -74,15 +73,13 @@ public function __construct(ObjectManager $manager, string $class, IdReader $idR */ public function loadChoiceList($value = null) { - if ($this->choiceList) { - return $this->choiceList; + if (null === $this->choices) { + $this->choices = $this->objectLoader + ? $this->objectLoader->getEntities() + : $this->manager->getRepository($this->class)->findAll(); } - $objects = $this->objectLoader - ? $this->objectLoader->getEntities() - : $this->manager->getRepository($this->class)->findAll(); - - return $this->choiceList = new ArrayChoiceList($objects, $value); + return new ArrayChoiceList($this->choices, $value); } /** @@ -100,7 +97,7 @@ public function loadValuesForChoices(array $choices, $value = null) $optimize = $this->idReader && (null === $value || \is_array($value) && $value[0] === $this->idReader); // Attention: This optimization does not check choices for existence - if ($optimize && !$this->choiceList && $this->idReader->isSingleId()) { + if ($optimize && !$this->choices && $this->idReader->isSingleId()) { $values = []; // Maintain order and indices of the given objects @@ -136,7 +133,7 @@ public function loadChoicesForValues(array $values, $value = null) // a single-field identifier $optimize = $this->idReader && (null === $value || \is_array($value) && $this->idReader === $value[0]); - if ($optimize && !$this->choiceList && $this->objectLoader && $this->idReader->isSingleId()) { + if ($optimize && !$this->choices && $this->objectLoader && $this->idReader->isSingleId()) { $unorderedObjects = $this->objectLoader->getEntitiesByIds($this->idReader->getIdField(), $values); $objectsById = []; $objects = []; diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php index 004eec8201336..29da316d20feb 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php @@ -146,8 +146,7 @@ public function testLoadChoiceListUsesObjectLoaderIfAvailable() $this->assertEquals($choiceList, $loaded = $loader->loadChoiceList()); // no further loads on subsequent calls - - $this->assertSame($loaded, $loader->loadChoiceList()); + $this->assertEquals($loaded, $loader->loadChoiceList()); } public function testLoadValuesForChoices() diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index cb7eeed32bbf2..f593618f9c8ff 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -1779,4 +1779,32 @@ public function testSubmitNullMultipleUsesDefaultEmptyData() $this->assertEquals($collection, $form->getNormData()); $this->assertEquals($collection, $form->getData()); } + + public function testWithSameLoaderAndDifferentChoiceValueCallbacks() + { + $entity1 = new SingleIntIdEntity(1, 'Foo'); + $entity2 = new SingleIntIdEntity(2, 'Bar'); + $this->persist([$entity1, $entity2]); + + $view = $this->factory->create(FormTypeTest::TESTED_TYPE) + ->add('entity_one', self::TESTED_TYPE, [ + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + ]) + ->add('entity_two', self::TESTED_TYPE, [ + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + 'choice_value' => function ($choice) { + return $choice ? $choice->name : ''; + }, + ]) + ->createView() + ; + + $this->assertSame('1', $view['entity_one']->vars['choices'][1]->value); + $this->assertSame('2', $view['entity_one']->vars['choices'][2]->value); + + $this->assertSame('Foo', $view['entity_two']->vars['choices']['Foo']->value); + $this->assertSame('Bar', $view['entity_two']->vars['choices']['Bar']->value); + } } diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index f14aa99bc8ad4..b4ebc03d319fb 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -29,7 +29,7 @@ "symfony/stopwatch": "^3.4|^4.0|^5.0", "symfony/config": "^4.2|^5.0", "symfony/dependency-injection": "^3.4|^4.0|^5.0", - "symfony/form": "^4.4.11|^5.0.11", + "symfony/form": "^4.4.41|^5.0.11", "symfony/http-kernel": "^4.3.7", "symfony/messenger": "^4.4|^5.0", "symfony/property-access": "^3.4|^4.0|^5.0", diff --git a/src/Symfony/Component/Form/ChoiceList/Loader/CallbackChoiceLoader.php b/src/Symfony/Component/Form/ChoiceList/Loader/CallbackChoiceLoader.php index 2d6782f558aea..944d6a48826af 100644 --- a/src/Symfony/Component/Form/ChoiceList/Loader/CallbackChoiceLoader.php +++ b/src/Symfony/Component/Form/ChoiceList/Loader/CallbackChoiceLoader.php @@ -23,11 +23,11 @@ class CallbackChoiceLoader implements ChoiceLoaderInterface private $callback; /** - * The loaded choice list. + * The loaded choices. * - * @var ArrayChoiceList + * @var array|null */ - private $choiceList; + private $choices; /** * @param callable $callback The callable returning an array of choices @@ -42,11 +42,11 @@ public function __construct(callable $callback) */ public function loadChoiceList($value = null) { - if (null !== $this->choiceList) { - return $this->choiceList; + if (null === $this->choices) { + $this->choices = ($this->callback)(); } - return $this->choiceList = new ArrayChoiceList(($this->callback)(), $value); + return new ArrayChoiceList($this->choices, $value); } /** diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/LazyChoiceListTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/LazyChoiceListTest.php index 6f30d0896e1ba..94d41cf9e740f 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/LazyChoiceListTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/LazyChoiceListTest.php @@ -32,7 +32,7 @@ public function testGetChoiceLoadersLoadsLoadedListOnFirstCall() $this->assertSame(['RESULT'], $list->getChoices()); $this->assertSame(['RESULT'], $list->getChoices()); - $this->assertSame(1, $calls); + $this->assertSame(2, $calls); } public function testGetValuesLoadsLoadedListOnFirstCall() @@ -46,7 +46,7 @@ public function testGetValuesLoadsLoadedListOnFirstCall() $this->assertSame(['RESULT'], $list->getValues()); $this->assertSame(['RESULT'], $list->getValues()); - $this->assertSame(1, $calls); + $this->assertSame(2, $calls); } public function testGetStructuredValuesLoadsLoadedListOnFirstCall() @@ -60,7 +60,7 @@ public function testGetStructuredValuesLoadsLoadedListOnFirstCall() $this->assertSame(['RESULT'], $list->getStructuredValues()); $this->assertSame(['RESULT'], $list->getStructuredValues()); - $this->assertSame(1, $calls); + $this->assertSame(2, $calls); } public function testGetOriginalKeysLoadsLoadedListOnFirstCall() @@ -79,7 +79,7 @@ public function testGetOriginalKeysLoadsLoadedListOnFirstCall() $this->assertSame(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $list->getOriginalKeys()); $this->assertSame(['foo' => 'a', 'bar' => 'b', 'baz' => 'c'], $list->getOriginalKeys()); - $this->assertSame(3, $calls); + $this->assertSame(6, $calls); } public function testGetChoicesForValuesForwardsCallIfListNotLoaded() @@ -98,7 +98,7 @@ public function testGetChoicesForValuesForwardsCallIfListNotLoaded() $this->assertSame(['foo', 'bar'], $list->getChoicesForValues(['a', 'b'])); $this->assertSame(['foo', 'bar'], $list->getChoicesForValues(['a', 'b'])); - $this->assertSame(3, $calls); + $this->assertSame(6, $calls); } public function testGetChoicesForValuesUsesLoadedList() diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Loader/CallbackChoiceLoaderTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Loader/CallbackChoiceLoaderTest.php index 52dd5f8af580f..69eb787a23dfa 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Loader/CallbackChoiceLoaderTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Loader/CallbackChoiceLoaderTest.php @@ -67,11 +67,18 @@ public function testLoadChoiceList() $this->assertInstanceOf(ChoiceListInterface::class, self::$loader->loadChoiceList(self::$value)); } - public function testLoadChoiceListOnlyOnce() + public function testLoadChoicesOnlyOnce() { - $loadedChoiceList = self::$loader->loadChoiceList(self::$value); + $calls = 0; + $loader = new CallbackChoiceLoader(function () use (&$calls) { + ++$calls; - $this->assertSame($loadedChoiceList, self::$loader->loadChoiceList(self::$value)); + return [1]; + }); + $loadedChoiceList = $loader->loadChoiceList(); + + $this->assertNotSame($loadedChoiceList, $loader->loadChoiceList()); + $this->assertSame(1, $calls); } public function testLoadChoicesForValuesLoadsChoiceListOnFirstCall() diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Loader/IntlCallbackChoiceLoaderTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Loader/IntlCallbackChoiceLoaderTest.php index a5fc262dcd3a1..e2827b0d913be 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Loader/IntlCallbackChoiceLoaderTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Loader/IntlCallbackChoiceLoaderTest.php @@ -68,11 +68,19 @@ public function testLoadChoiceList() $this->assertInstanceOf(ChoiceListInterface::class, self::$loader->loadChoiceList(self::$value)); } - public function testLoadChoiceListOnlyOnce() + public function testLoadChoicesOnlyOnce() { - $loadedChoiceList = self::$loader->loadChoiceList(self::$value); + $calls = 0; + $loader = new IntlCallbackChoiceLoader(function () use (&$calls) { + ++$calls; - $this->assertSame($loadedChoiceList, self::$loader->loadChoiceList(self::$value)); + return self::$choices; + }); + + $loadedChoiceList = $loader->loadChoiceList(self::$value); + + $this->assertNotSame($loadedChoiceList, $loader->loadChoiceList(self::$value)); + $this->assertSame(1, $calls); } public function testLoadChoicesForValuesLoadsChoiceListOnFirstCall() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 1bf30575275f9..0da56921d93ed 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type; +use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader; use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView; use Symfony\Component\Form\ChoiceList\View\ChoiceView; use Symfony\Component\Form\Extension\Validator\ValidatorExtension; @@ -2165,4 +2166,32 @@ public function expandedIsEmptyWhenNoRealChoiceIsSelectedProvider() 'Placeholder submitted / single / not required / with a placeholder -> should not be empty' => [false, '', false, false, 'ccc'], // The placeholder is a selected value ]; } + + public function testWithSameLoaderAndDifferentChoiceValueCallbacks() + { + $choiceLoader = new CallbackChoiceLoader(function () { + return [1, 2, 3]; + }); + + $view = $this->factory->create(FormTypeTest::TESTED_TYPE) + ->add('choice_one', self::TESTED_TYPE, [ + 'choice_loader' => $choiceLoader, + ]) + ->add('choice_two', self::TESTED_TYPE, [ + 'choice_loader' => $choiceLoader, + 'choice_value' => function ($choice) { + return $choice ? (string) $choice * 10 : ''; + }, + ]) + ->createView() + ; + + $this->assertSame('1', $view['choice_one']->vars['choices'][0]->value); + $this->assertSame('2', $view['choice_one']->vars['choices'][1]->value); + $this->assertSame('3', $view['choice_one']->vars['choices'][2]->value); + + $this->assertSame('10', $view['choice_two']->vars['choices'][0]->value); + $this->assertSame('20', $view['choice_two']->vars['choices'][1]->value); + $this->assertSame('30', $view['choice_two']->vars['choices'][2]->value); + } } From ac66fd5594b406e7a723df14a9263e4e97de6a40 Mon Sep 17 00:00:00 2001 From: Konrad Date: Fri, 20 May 2022 12:18:02 +0200 Subject: [PATCH 23/48] Bootstrap 4 fieldset for row errors --- .../Resources/views/Form/bootstrap_4_horizontal_layout.html.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig index a75e364187743..990b324cb0d17 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig @@ -49,6 +49,7 @@ col-sm-2
{{- form_widget(form, widget_attr) -}} {{- form_help(form) -}} + {{- form_errors(form) -}}
{##} From 3051dff87c96a5c86f29808f49f130b4352bbb90 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 20 May 2022 16:06:40 +0200 Subject: [PATCH 24/48] fix merge --- src/Symfony/Bridge/Doctrine/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index ebe340ca9f40f..407e0d4d084e7 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -30,7 +30,7 @@ "symfony/cache": "^5.4|^6.0", "symfony/config": "^4.4|^5.0|^6.0", "symfony/dependency-injection": "^4.4|^5.0|^6.0", - "symfony/form": "^5.1.3|^6.0", + "symfony/form": "^5.4.9|^6.0", "symfony/http-kernel": "^5.0|^6.0", "symfony/messenger": "^4.4|^5.0|^6.0", "symfony/doctrine-messenger": "^5.1|^6.0", From 1193ed21db2e92ac46a0f7cef840f0d16361e268 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Tue, 17 May 2022 13:08:02 -0400 Subject: [PATCH 25/48] New bundle path convention when AbstractBundle is used --- .../Component/HttpKernel/Bundle/AbstractBundle.php | 14 ++++++++++++++ src/Symfony/Component/HttpKernel/CHANGELOG.md | 1 + 2 files changed, 15 insertions(+) diff --git a/src/Symfony/Component/HttpKernel/Bundle/AbstractBundle.php b/src/Symfony/Component/HttpKernel/Bundle/AbstractBundle.php index 3e6029f8c2510..244f3ec32b0b2 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/AbstractBundle.php +++ b/src/Symfony/Component/HttpKernel/Bundle/AbstractBundle.php @@ -47,4 +47,18 @@ public function getContainerExtension(): ?ExtensionInterface return $this->extension ??= new BundleExtension($this, $this->extensionAlias); } + + /** + * {@inheritdoc} + */ + public function getPath(): string + { + if (null === $this->path) { + $reflected = new \ReflectionObject($this); + // assume the modern directory structure by default + $this->path = \dirname($reflected->getFileName(), 2); + } + + return $this->path; + } } diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index 6c40b7da3a66a..bb26bd4145017 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG * Add `Profiler::isEnabled()` so collaborating collector services may elect to omit themselves * Add the `UidValueResolver` argument value resolver * Add `AbstractBundle` class for DI configuration/definition on a single file + * Update the path of a bundle placed in the `src/` directory to the parent directory when `AbstractBundle` is used 6.0 --- From cdc9414c9fe7ec32c786b6f76391113f3a20d605 Mon Sep 17 00:00:00 2001 From: buffcode Date: Wed, 18 May 2022 23:39:15 +0200 Subject: [PATCH 26/48] [Cache] Throw when "redis_sentinel" is used with a non-Predis "class" option --- .../Cache/Tests/Adapter/RedisAdapterSentinelTest.php | 9 +++++++++ src/Symfony/Component/Cache/Traits/RedisTrait.php | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php b/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php index c8b3ce9b9da62..b79a5069f362f 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\SkippedTestSuiteError; use Symfony\Component\Cache\Adapter\AbstractAdapter; use Symfony\Component\Cache\Adapter\RedisAdapter; +use Symfony\Component\Cache\Exception\CacheException; use Symfony\Component\Cache\Exception\InvalidArgumentException; /** @@ -43,4 +44,12 @@ public function testInvalidDSNHasBothClusterAndSentinel() $dsn = 'redis:?host[redis1]&host[redis2]&host[redis3]&redis_cluster=1&redis_sentinel=mymaster'; RedisAdapter::createConnection($dsn); } + + public function testSentinelRequiresPredis() + { + $this->expectException(CacheException::class); + $this->expectExceptionMessage('Cannot use Redis Sentinel: class "Redis" does not extend "Predis\Client":'); + $dsn = 'redis:?host[redis1]&host[redis2]&host[redis3]&redis_cluster=1&redis_sentinel=mymaster'; + RedisAdapter::createConnection($dsn, ['class' => \Redis::class]); + } } diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.php index efff27296628d..c27e0df689493 100644 --- a/src/Symfony/Component/Cache/Traits/RedisTrait.php +++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php @@ -178,6 +178,10 @@ public static function createConnection($dsn, array $options = []) $class = $params['redis_cluster'] ? \RedisCluster::class : (1 < \count($hosts) ? \RedisArray::class : \Redis::class); } else { $class = $params['class'] ?? \Predis\Client::class; + + if (isset($params['redis_sentinel']) && !is_a($class, \Predis\Client::class, true)) { + throw new CacheException(sprintf('Cannot use Redis Sentinel: class "%s" does not extend "Predis\Client": "%s".', $class, $dsn)); + } } if (is_a($class, \Redis::class, true)) { From 9319a7ad2f026ec1ba404a070b1c5c85b394e12e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 21 May 2022 11:56:12 +0200 Subject: [PATCH 27/48] [VarDumper][VarExporter] Deal with DatePeriod->include_end_date on PHP 8.2 --- .../Component/VarDumper/Caster/DateCaster.php | 6 ++-- .../VarDumper/Tests/Caster/DateCasterTest.php | 28 +++++++++---------- .../VarExporter/Tests/Fixtures/datetime.php | 1 + 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/VarDumper/Caster/DateCaster.php b/src/Symfony/Component/VarDumper/Caster/DateCaster.php index 1b195f49e5386..e0309bc62d963 100644 --- a/src/Symfony/Component/VarDumper/Caster/DateCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/DateCaster.php @@ -105,11 +105,11 @@ public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, $isNeste } $period = sprintf( - 'every %s, from %s (%s) %s', + 'every %s, from %s%s %s', self::formatInterval($p->getDateInterval()), + $p->include_start_date ? '[' : ']', self::formatDateTime($p->getStartDate()), - $p->include_start_date ? 'included' : 'excluded', - ($end = $p->getEndDate()) ? 'to '.self::formatDateTime($end) : 'recurring '.$p->recurrences.' time/s' + ($end = $p->getEndDate()) ? 'to '.self::formatDateTime($end).(\PHP_VERSION_ID >= 80200 && $p->include_end_date ? ']' : '[') : 'recurring '.$p->recurrences.' time/s' ); $p = [Caster::PREFIX_VIRTUAL.'period' => new ConstStub($period, implode("\n", $dates))]; diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php index 63be1681d0649..ba3b5dea77f49 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php @@ -385,26 +385,26 @@ public function testCastPeriod($start, $interval, $end, $options, $xPeriod, $xDa public function providePeriods() { $periods = [ - ['2017-01-01', 'P1D', '2017-01-03', 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) to 2017-01-03 00:00:00.0', '1) 2017-01-01%a2) 2017-01-02'], - ['2017-01-01', 'P1D', 1, 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) recurring 2 time/s', '1) 2017-01-01%a2) 2017-01-02'], + ['2017-01-01', 'P1D', '2017-01-03', 0, 'every + 1d, from [2017-01-01 00:00:00.0 to 2017-01-03 00:00:00.0[', '1) 2017-01-01%a2) 2017-01-02'], + ['2017-01-01', 'P1D', 1, 0, 'every + 1d, from [2017-01-01 00:00:00.0 recurring 2 time/s', '1) 2017-01-01%a2) 2017-01-02'], - ['2017-01-01', 'P1D', '2017-01-04', 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) to 2017-01-04 00:00:00.0', '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03'], - ['2017-01-01', 'P1D', 2, 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) recurring 3 time/s', '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03'], + ['2017-01-01', 'P1D', '2017-01-04', 0, 'every + 1d, from [2017-01-01 00:00:00.0 to 2017-01-04 00:00:00.0[', '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03'], + ['2017-01-01', 'P1D', 2, 0, 'every + 1d, from [2017-01-01 00:00:00.0 recurring 3 time/s', '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03'], - ['2017-01-01', 'P1D', '2017-01-05', 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) to 2017-01-05 00:00:00.0', '1) 2017-01-01%a2) 2017-01-02%a1 more'], - ['2017-01-01', 'P1D', 3, 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) recurring 4 time/s', '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03%a1 more'], + ['2017-01-01', 'P1D', '2017-01-05', 0, 'every + 1d, from [2017-01-01 00:00:00.0 to 2017-01-05 00:00:00.0[', '1) 2017-01-01%a2) 2017-01-02%a1 more'], + ['2017-01-01', 'P1D', 3, 0, 'every + 1d, from [2017-01-01 00:00:00.0 recurring 4 time/s', '1) 2017-01-01%a2) 2017-01-02%a3) 2017-01-03%a1 more'], - ['2017-01-01', 'P1D', '2017-01-21', 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) to 2017-01-21 00:00:00.0', '1) 2017-01-01%a17 more'], - ['2017-01-01', 'P1D', 19, 0, 'every + 1d, from 2017-01-01 00:00:00.0 (included) recurring 20 time/s', '1) 2017-01-01%a17 more'], + ['2017-01-01', 'P1D', '2017-01-21', 0, 'every + 1d, from [2017-01-01 00:00:00.0 to 2017-01-21 00:00:00.0[', '1) 2017-01-01%a17 more'], + ['2017-01-01', 'P1D', 19, 0, 'every + 1d, from [2017-01-01 00:00:00.0 recurring 20 time/s', '1) 2017-01-01%a17 more'], - ['2017-01-01 01:00:00', 'P1D', '2017-01-03 01:00:00', 0, 'every + 1d, from 2017-01-01 01:00:00.0 (included) to 2017-01-03 01:00:00.0', '1) 2017-01-01 01:00:00.0%a2) 2017-01-02 01:00:00.0'], - ['2017-01-01 01:00:00', 'P1D', 1, 0, 'every + 1d, from 2017-01-01 01:00:00.0 (included) recurring 2 time/s', '1) 2017-01-01 01:00:00.0%a2) 2017-01-02 01:00:00.0'], + ['2017-01-01 01:00:00', 'P1D', '2017-01-03 01:00:00', 0, 'every + 1d, from [2017-01-01 01:00:00.0 to 2017-01-03 01:00:00.0[', '1) 2017-01-01 01:00:00.0%a2) 2017-01-02 01:00:00.0'], + ['2017-01-01 01:00:00', 'P1D', 1, 0, 'every + 1d, from [2017-01-01 01:00:00.0 recurring 2 time/s', '1) 2017-01-01 01:00:00.0%a2) 2017-01-02 01:00:00.0'], - ['2017-01-01', 'P1DT1H', '2017-01-03', 0, 'every + 1d 01:00:00.0, from 2017-01-01 00:00:00.0 (included) to 2017-01-03 00:00:00.0', '1) 2017-01-01 00:00:00.0%a2) 2017-01-02 01:00:00.0'], - ['2017-01-01', 'P1DT1H', 1, 0, 'every + 1d 01:00:00.0, from 2017-01-01 00:00:00.0 (included) recurring 2 time/s', '1) 2017-01-01 00:00:00.0%a2) 2017-01-02 01:00:00.0'], + ['2017-01-01', 'P1DT1H', '2017-01-03', 0, 'every + 1d 01:00:00.0, from [2017-01-01 00:00:00.0 to 2017-01-03 00:00:00.0[', '1) 2017-01-01 00:00:00.0%a2) 2017-01-02 01:00:00.0'], + ['2017-01-01', 'P1DT1H', 1, 0, 'every + 1d 01:00:00.0, from [2017-01-01 00:00:00.0 recurring 2 time/s', '1) 2017-01-01 00:00:00.0%a2) 2017-01-02 01:00:00.0'], - ['2017-01-01', 'P1D', '2017-01-04', \DatePeriod::EXCLUDE_START_DATE, 'every + 1d, from 2017-01-01 00:00:00.0 (excluded) to 2017-01-04 00:00:00.0', '1) 2017-01-02%a2) 2017-01-03'], - ['2017-01-01', 'P1D', 2, \DatePeriod::EXCLUDE_START_DATE, 'every + 1d, from 2017-01-01 00:00:00.0 (excluded) recurring 2 time/s', '1) 2017-01-02%a2) 2017-01-03'], + ['2017-01-01', 'P1D', '2017-01-04', \DatePeriod::EXCLUDE_START_DATE, 'every + 1d, from ]2017-01-01 00:00:00.0 to 2017-01-04 00:00:00.0[', '1) 2017-01-02%a2) 2017-01-03'], + ['2017-01-01', 'P1D', 2, \DatePeriod::EXCLUDE_START_DATE, 'every + 1d, from ]2017-01-01 00:00:00.0 recurring 2 time/s', '1) 2017-01-02%a2) 2017-01-03'], ]; if (\PHP_VERSION_ID < 70107) { diff --git a/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php b/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php index 6429f10efe9f1..7078ef2525674 100644 --- a/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php +++ b/src/Symfony/Component/VarExporter/Tests/Fixtures/datetime.php @@ -70,6 +70,7 @@ 'interval' => $o[6], 'recurrences' => 5, 'include_start_date' => true, + 'include_end_date' => false, ], ] ); From 8561c4e91f45da45bbd5f4a5d2eb6cc5820dcc68 Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Mon, 16 May 2022 23:52:41 +0200 Subject: [PATCH 28/48] [Mime] Throw exception when body in Email attach method is not ok --- src/Symfony/Component/Mime/Email.php | 20 +++++- .../Component/Mime/Tests/EmailTest.php | 62 +++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Mime/Email.php b/src/Symfony/Component/Mime/Email.php index 7a7a0db32e167..5e31cb92a85f2 100644 --- a/src/Symfony/Component/Mime/Email.php +++ b/src/Symfony/Component/Mime/Email.php @@ -272,12 +272,16 @@ public function getPriority(): int } /** - * @param resource|string $body + * @param resource|string|null $body * * @return $this */ public function text($body, string $charset = 'utf-8') { + if (null !== $body && !\is_string($body) && !\is_resource($body)) { + throw new \TypeError(sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body))); + } + $this->text = $body; $this->textCharset = $charset; @@ -304,6 +308,10 @@ public function getTextCharset(): ?string */ public function html($body, string $charset = 'utf-8') { + if (null !== $body && !\is_string($body) && !\is_resource($body)) { + throw new \TypeError(sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body))); + } + $this->html = $body; $this->htmlCharset = $charset; @@ -330,6 +338,10 @@ public function getHtmlCharset(): ?string */ public function attach($body, string $name = null, string $contentType = null) { + if (!\is_string($body) && !\is_resource($body)) { + throw new \TypeError(sprintf('The body must be a string or a resource (got "%s").', get_debug_type($body))); + } + $this->attachments[] = ['body' => $body, 'name' => $name, 'content-type' => $contentType, 'inline' => false]; return $this; @@ -352,6 +364,10 @@ public function attachFromPath(string $path, string $name = null, string $conten */ public function embed($body, string $name = null, string $contentType = null) { + if (!\is_string($body) && !\is_resource($body)) { + throw new \TypeError(sprintf('The body must be a string or a resource (got "%s").', get_debug_type($body))); + } + $this->attachments[] = ['body' => $body, 'name' => $name, 'content-type' => $contentType, 'inline' => true]; return $this; @@ -463,7 +479,7 @@ private function prepareParts(): ?array $names = []; $htmlPart = null; $html = $this->html; - if (null !== $this->html) { + if (null !== $html) { if (\is_resource($html)) { if (stream_get_meta_data($html)['seekable'] ?? false) { rewind($html); diff --git a/src/Symfony/Component/Mime/Tests/EmailTest.php b/src/Symfony/Component/Mime/Tests/EmailTest.php index baffa4a4e0655..a12ca180e611c 100644 --- a/src/Symfony/Component/Mime/Tests/EmailTest.php +++ b/src/Symfony/Component/Mime/Tests/EmailTest.php @@ -396,4 +396,66 @@ public function testMissingHeaderDoesNotThrowError() $emailHeaderSame = new EmailHeaderSame('foo', 'bar'); $emailHeaderSame->evaluate($e); } + + public function testAttachBodyExpectStringOrResource() + { + $this->expectException(\TypeError::class); + $this->expectExceptionMessage('The body must be a string or a resource (got "bool").'); + + (new Email())->attach(false); + } + + public function testEmbedBodyExpectStringOrResource() + { + $this->expectException(\TypeError::class); + $this->expectExceptionMessage('The body must be a string or a resource (got "bool").'); + + (new Email())->embed(false); + } + + public function testHtmlBodyExpectStringOrResourceOrNull() + { + $this->expectException(\TypeError::class); + $this->expectExceptionMessage('The body must be a string, a resource or null (got "bool").'); + + (new Email())->html(false); + } + + public function testHtmlBodyAcceptedTypes() + { + $email = new Email(); + + $email->html('foo'); + $this->assertSame('foo', $email->getHtmlBody()); + + $email->html(null); + $this->assertNull($email->getHtmlBody()); + + $contents = file_get_contents(__DIR__.'/Fixtures/mimetypes/test', 'r'); + $email->html($contents); + $this->assertSame($contents, $email->getHtmlBody()); + } + + public function testTextBodyExpectStringOrResourceOrNull() + { + $this->expectException(\TypeError::class); + $this->expectExceptionMessage('The body must be a string, a resource or null (got "bool").'); + + (new Email())->text(false); + } + + public function testTextBodyAcceptedTypes() + { + $email = new Email(); + + $email->text('foo'); + $this->assertSame('foo', $email->getTextBody()); + + $email->text(null); + $this->assertNull($email->getTextBody()); + + $contents = file_get_contents(__DIR__.'/Fixtures/mimetypes/test', 'r'); + $email->text($contents); + $this->assertSame($contents, $email->getTextBody()); + } } From 400f4432b1b0678a166fdf1b488e53e7c4d25946 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 21 May 2022 15:19:01 +0200 Subject: [PATCH 29/48] Fix merge --- .../Bundle/FrameworkBundle/Command/ConfigDebugCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php index 3d28dfb3a46af..ab789852156e1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php @@ -197,7 +197,8 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti if ($input->mustSuggestArgumentValuesFor('path') && null !== $name = $input->getArgument('name')) { try { - $config = $this->getConfig($this->findExtension($name), $this->compileContainer()); + $container = $this->compileContainer(); + $config = $this->getConfig($this->findExtension($name, $container), $container); $paths = array_keys(self::buildPathsCompletion($config)); $suggestions->suggestValues($paths); } catch (LogicException $e) { From 054b54391951a180b854b1263c1c4e03ebcdf575 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 21 May 2022 15:41:46 +0200 Subject: [PATCH 30/48] [FrameworkBundle] fix tests --- .../Tests/Functional/Extension/TestDumpExtension.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php index 17738adf1b151..d8cef92850992 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php @@ -18,7 +18,7 @@ class TestDumpExtension extends Extension implements ConfigurationInterface { - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('test_dump'); $treeBuilder->getRootNode() @@ -30,11 +30,11 @@ public function getConfigTreeBuilder() return $treeBuilder; } - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { } - public function getConfiguration(array $config, ContainerBuilder $container) + public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface { return $this; } From d3edf4c4663b6529e72cd99efc2a80152e806b05 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 21 May 2022 15:57:48 +0200 Subject: [PATCH 31/48] [ErrorHandler] update tentative types --- .../Component/ErrorHandler/Internal/TentativeTypes.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/ErrorHandler/Internal/TentativeTypes.php b/src/Symfony/Component/ErrorHandler/Internal/TentativeTypes.php index ee403b3d1b078..2168a1c075816 100644 --- a/src/Symfony/Component/ErrorHandler/Internal/TentativeTypes.php +++ b/src/Symfony/Component/ErrorHandler/Internal/TentativeTypes.php @@ -37,7 +37,7 @@ class TentativeTypes 'DateTime' => [ '__wakeup' => 'void', '__set_state' => 'DateTime', - 'createFromImmutable' => 'DateTime', + 'createFromImmutable' => 'static', 'createFromFormat' => 'DateTime|false', 'getLastErrors' => 'array|false', 'format' => 'string', @@ -72,7 +72,7 @@ class TentativeTypes 'setDate' => 'DateTimeImmutable', 'setISODate' => 'DateTimeImmutable', 'setTimestamp' => 'DateTimeImmutable', - 'createFromMutable' => 'DateTimeImmutable', + 'createFromMutable' => 'static', ], 'DateTimeZone' => [ 'getName' => 'string', @@ -1150,8 +1150,8 @@ class TentativeTypes 'getFlags' => 'int', 'setMaxLineLen' => 'void', 'getMaxLineLen' => 'int', - 'hasChildren' => 'bool', - 'getChildren' => '?RecursiveIterator', + 'hasChildren' => 'false', + 'getChildren' => 'null', 'seek' => 'void', 'getCurrentLine' => 'string', ], @@ -1240,7 +1240,7 @@ class TentativeTypes 'current' => 'never', 'next' => 'void', 'key' => 'never', - 'valid' => 'bool', + 'valid' => 'false', 'rewind' => 'void', ], 'CallbackFilterIterator' => [ From d92da280d86473ecbe2f6ca210781f30659d982e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 21 May 2022 15:59:52 +0200 Subject: [PATCH 32/48] Update PR template --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e6333054fe172..58caff2209f37 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,6 +1,6 @@ | Q | A | ------------- | --- -| Branch? | 6.1 for features / 4.4, 5.4 or 6.0 for bug fixes +| Branch? | 6.2 for features / 4.4, 5.4, 6.0 or 6.1 for bug fixes | Bug fix? | yes/no | New feature? | yes/no | Deprecations? | yes/no From 6bffdbc09df5f67b284408e66d076666435146b5 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 21 May 2022 15:56:43 +0200 Subject: [PATCH 33/48] do not accept array input when a form is not multiple --- src/Symfony/Component/Form/Form.php | 2 +- src/Symfony/Component/Form/Tests/CompoundFormTest.php | 3 ++- .../Form/Tests/Extension/Core/Type/ChoiceTypeTest.php | 8 +++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 32cc437574d4b..5f00c7aa2eed0 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -547,7 +547,7 @@ public function submit($submittedData, $clearMissing = true) $submittedData = null; $this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, file upload given.'); } - } elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->hasOption('multiple')) { + } elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->getOption('multiple', false)) { $submittedData = null; $this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, array given.'); } diff --git a/src/Symfony/Component/Form/Tests/CompoundFormTest.php b/src/Symfony/Component/Form/Tests/CompoundFormTest.php index 7f8548e7a4158..ec05102496613 100644 --- a/src/Symfony/Component/Form/Tests/CompoundFormTest.php +++ b/src/Symfony/Component/Form/Tests/CompoundFormTest.php @@ -1057,7 +1057,8 @@ public function testArrayTransformationFailureOnSubmit() $this->assertNull($this->form->get('foo')->getData()); $this->assertSame('Submitted data was expected to be text or number, array given.', $this->form->get('foo')->getTransformationFailure()->getMessage()); - $this->assertSame(['bar'], $this->form->get('bar')->getData()); + $this->assertNull($this->form->get('bar')->getData()); + $this->assertSame('Submitted data was expected to be text or number, array given.', $this->form->get('bar')->getTransformationFailure()->getMessage()); } public function testFileUpload() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 0da56921d93ed..ebd2dd61849bc 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -14,6 +14,7 @@ use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader; use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView; use Symfony\Component\Form\ChoiceList\View\ChoiceView; +use Symfony\Component\Form\Exception\TransformationFailedException; use Symfony\Component\Form\Extension\Validator\ValidatorExtension; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\Forms; @@ -1918,7 +1919,12 @@ public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionDa $form->submit($submissionData); $this->assertFalse($form->isSynchronized()); - $this->assertEquals('All choices submitted must be NULL, strings or ints.', $form->getTransformationFailure()->getMessage()); + $this->assertInstanceOf(TransformationFailedException::class, $form->getTransformationFailure()); + if (!$multiple && !$expanded) { + $this->assertEquals('Submitted data was expected to be text or number, array given.', $form->getTransformationFailure()->getMessage()); + } else { + $this->assertEquals('All choices submitted must be NULL, strings or ints.', $form->getTransformationFailure()->getMessage()); + } } public function invalidNestedValueTestMatrix() From b325f8be408438265b378b61203344f727b6646a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 21 May 2022 16:25:37 +0200 Subject: [PATCH 34/48] [DependencyInjection] Ignore unused bindings defined by attribute --- .../Compiler/RegisterAutoconfigureAttributesPass.php | 3 ++- .../DependencyInjection/Loader/YamlFileLoader.php | 10 +++++----- .../RegisterAutoconfigureAttributesPassTest.php | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php index 08befc4dda12f..cc3b117a4df5e 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php @@ -82,7 +82,8 @@ private static function registerForAutoconfiguration(ContainerBuilder $container ], ], ], - $class->getFileName() + $class->getFileName(), + false ); }; diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 7efda3c43c17f..01e20c44edf94 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -220,7 +220,7 @@ private function parseImports(array $content, string $file) } } - private function parseDefinitions(array $content, string $file) + private function parseDefinitions(array $content, string $file, bool $trackBindings = true) { if (!isset($content['services'])) { return; @@ -246,14 +246,14 @@ private function parseDefinitions(array $content, string $file) if (\is_string($service) && str_starts_with($service, '@')) { throw new InvalidArgumentException(sprintf('Type definition "%s" cannot be an alias within "_instanceof" in "%s". Check your YAML syntax.', $id, $file)); } - $this->parseDefinition($id, $service, $file, []); + $this->parseDefinition($id, $service, $file, [], false, $trackBindings); } } $this->isLoadingInstanceof = false; $defaults = $this->parseDefaults($content, $file); foreach ($content['services'] as $id => $service) { - $this->parseDefinition($id, $service, $file, $defaults); + $this->parseDefinition($id, $service, $file, $defaults, false, $trackBindings); } } @@ -342,7 +342,7 @@ private function isUsingShortSyntax(array $service): bool * * @throws InvalidArgumentException When tags are invalid */ - private function parseDefinition(string $id, $service, string $file, array $defaults, bool $return = false) + private function parseDefinition(string $id, $service, string $file, array $defaults, bool $return = false, bool $trackBindings = true) { if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) { throw new InvalidArgumentException(sprintf('Service names that start with an underscore are reserved. Rename the "%s" service or define it in XML instead.', $id)); @@ -666,7 +666,7 @@ private function parseDefinition(string $id, $service, string $file, array $defa $bindingType = $this->isLoadingInstanceof ? BoundArgument::INSTANCEOF_BINDING : BoundArgument::SERVICE_BINDING; foreach ($bindings as $argument => $value) { if (!$value instanceof BoundArgument) { - $bindings[$argument] = new BoundArgument($value, true, $bindingType, $file); + $bindings[$argument] = new BoundArgument($value, $trackBindings, $bindingType, $file); } } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterAutoconfigureAttributesPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterAutoconfigureAttributesPassTest.php index 111c41ac8a114..793962f3e0466 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterAutoconfigureAttributesPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterAutoconfigureAttributesPassTest.php @@ -34,7 +34,7 @@ public function testProcess() (new RegisterAutoconfigureAttributesPass())->process($container); - $argument = new BoundArgument(1, true, BoundArgument::INSTANCEOF_BINDING, realpath(__DIR__.'/../Fixtures/AutoconfigureAttributed.php')); + $argument = new BoundArgument(1, false, BoundArgument::INSTANCEOF_BINDING, realpath(__DIR__.'/../Fixtures/AutoconfigureAttributed.php')); $values = $argument->getValues(); --$values[1]; $argument->setValues($values); From 5be61fa8b6c00a97da98c385b8224c9215a10987 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Sat, 21 May 2022 15:38:22 -0400 Subject: [PATCH 35/48] Fix BC break --- .../Bundle/FrameworkBundle/Command/AbstractConfigCommand.php | 5 +++-- .../Bundle/FrameworkBundle/Command/ConfigDebugCommand.php | 4 ++-- .../FrameworkBundle/Command/ConfigDumpReferenceCommand.php | 5 ++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php index a45c9c9c5fd8d..0ff799ba9bbc3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php @@ -16,7 +16,6 @@ use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\StyleInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; /** @@ -60,7 +59,7 @@ protected function listBundles($output) /** * @return ExtensionInterface */ - protected function findExtension($name, ContainerBuilder $container) + protected function findExtension($name) { $bundles = $this->initializeBundles(); $minScore = \INF; @@ -82,6 +81,8 @@ protected function findExtension($name, ContainerBuilder $container) } } + $container = $this->getContainerBuilder(); + if ($container->hasExtension($name)) { return $container->getExtension($name); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php index aa36b1fa80bdb..a0623f396127b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php @@ -79,9 +79,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - $container = $this->compileContainer(); - $extension = $this->findExtension($name, $container); + $extension = $this->findExtension($name); $extensionAlias = $extension->getAlias(); + $container = $this->compileContainer(); $config = $container->resolveEnvPlaceholders( $container->getParameterBag()->resolveValue( diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php index b104a1b806ca4..17690f7c99401 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php @@ -89,10 +89,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - $container = $this->getContainerBuilder(); - $extension = $this->findExtension($name, $container); + $extension = $this->findExtension($name); - $configuration = $extension->getConfiguration([], $container); + $configuration = $extension->getConfiguration([], $this->getContainerBuilder()); $this->validateConfiguration($extension, $configuration); From cfb2e14efa83d9c9e5db19fdd5f65c3bfd330a6a Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sun, 22 May 2022 17:14:14 +0200 Subject: [PATCH 36/48] [SecurityBundle] Remove dead `class_exists` checks --- .../Security/Factory/LdapFactoryTrait.php | 4 ---- .../Security/Factory/LoginLinkFactory.php | 5 ----- .../Security/Factory/LoginThrottlingFactory.php | 5 ----- 3 files changed, 14 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LdapFactoryTrait.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LdapFactoryTrait.php index 8af8e4424b270..deccbb3975469 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LdapFactoryTrait.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LdapFactoryTrait.php @@ -35,10 +35,6 @@ public function getKey(): string public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string { $key = str_replace('-', '_', $this->getKey()); - if (!class_exists(LdapAuthenticator::class)) { - throw new \LogicException(sprintf('The "%s" authenticator requires the "symfony/ldap" package version "5.1" or higher.', $key)); - } - $authenticatorId = parent::createAuthenticator($container, $firewallName, $config, $userProviderId); $container->setDefinition('security.listener.'.$key.'.'.$firewallName, new Definition(CheckLdapCredentialsListener::class)) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginLinkFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginLinkFactory.php index 5badfb237c5da..0c620e799799f 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginLinkFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginLinkFactory.php @@ -20,7 +20,6 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface; use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface; -use Symfony\Component\Security\Http\LoginLink\LoginLinkHandler; /** * @internal @@ -88,10 +87,6 @@ public function getKey(): string public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string { - if (!class_exists(LoginLinkHandler::class)) { - throw new \LogicException('Login login link requires symfony/security-http:^5.2.'); - } - if (!$container->hasDefinition('security.authenticator.login_link')) { $loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/../../Resources/config')); $loader->load('security_authenticator_login_link.php'); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginThrottlingFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginThrottlingFactory.php index dc829be2edd9e..9714fab632acc 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginThrottlingFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/LoginThrottlingFactory.php @@ -19,7 +19,6 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpFoundation\RateLimiter\RequestRateLimiterInterface; use Symfony\Component\RateLimiter\RateLimiterFactory; -use Symfony\Component\Security\Http\EventListener\LoginThrottlingListener; use Symfony\Component\Security\Http\RateLimiter\DefaultLoginRateLimiter; /** @@ -67,10 +66,6 @@ public function addConfiguration(NodeDefinition $builder) public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): array { - if (!class_exists(LoginThrottlingListener::class)) { - throw new \LogicException('Login throttling requires symfony/security-http:^5.2.'); - } - if (!class_exists(RateLimiterFactory::class)) { throw new \LogicException('Login throttling requires the Rate Limiter component. Try running "composer require symfony/rate-limiter".'); } From e32b7b15ec887a7da7b7c2835efeee582dc9223e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 21 May 2022 17:53:37 +0200 Subject: [PATCH 37/48] [FrameworkBundle] fix wiring of annotations.cached_reader --- .../AddAnnotationsCachedReaderPass.php | 1 - .../Compiler/UnusedTagsPass.php | 1 + .../FrameworkExtension.php | 4 +-- .../Resources/config/annotations.xml | 2 ++ .../FrameworkExtensionTest.php | 2 ++ .../Compiler/DecoratorServicePass.php | 8 ++++-- .../Compiler/InlineServiceDefinitionsPass.php | 2 +- .../InlineServiceDefinitionsPassTest.php | 28 +++++++++++++++++++ 8 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php index a0581ff21fb6f..d7db6ebf050a4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php @@ -29,7 +29,6 @@ public function process(ContainerBuilder $container) // "annotation_reader" at build time don't get any cache foreach ($container->findTaggedServiceIds('annotations.cached_reader') as $id => $tags) { $reader = $container->getDefinition($id); - $reader->setPublic(false); $properties = $reader->getProperties(); if (isset($properties['cacheProviderBackup'])) { diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php index 888a5ea8d64c1..669d331c062f3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php @@ -28,6 +28,7 @@ class UnusedTagsPass implements CompilerPassInterface 'cache.pool.clearer', 'config_cache.resource_checker', 'console.command', + 'container.do_not_inline', 'container.env_var_loader', 'container.env_var_processor', 'container.hot_path', diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 6f55ad6c38f39..ca338fc2054db 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -469,6 +469,8 @@ public function load(array $configs, ContainerBuilder $container) ->addTag('routing.route_loader'); $container->setParameter('container.behavior_describing_tags', [ + 'annotations.cached_reader', + 'container.do_not_inline', 'container.service_locator', 'container.service_subscriber', 'kernel.event_subscriber', @@ -1463,11 +1465,9 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde $container ->getDefinition('annotations.cached_reader') - ->setPublic(true) // set to false in AddAnnotationsCachedReaderPass ->replaceArgument(2, $config['debug']) // reference the cache provider without using it until AddAnnotationsCachedReaderPass runs ->addArgument(new ServiceClosureArgument(new Reference($cacheService))) - ->addTag('annotations.cached_reader') ; $container->setAlias('annotation_reader', 'annotations.cached_reader')->setPrivate(true); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml index 4420dfbf00db1..1fb375ea3c472 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml @@ -31,6 +31,8 @@ + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index b66d0837c3a37..c2c7bc6b851cc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1699,6 +1699,8 @@ public function testRegisterParameterCollectingBehaviorDescribingTags() $this->assertTrue($container->hasParameter('container.behavior_describing_tags')); $this->assertEquals([ + 'annotations.cached_reader', + 'container.do_not_inline', 'container.service_locator', 'container.service_subscriber', 'kernel.event_subscriber', diff --git a/src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php b/src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php index af7c957a308a2..3b8086d0931e6 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php @@ -40,6 +40,10 @@ public function process(ContainerBuilder $container) } $decoratingDefinitions = []; + $tagsToKeep = $container->hasParameter('container.behavior_describing_tags') + ? $container->getParameter('container.behavior_describing_tags') + : ['container.do_not_inline', 'container.service_locator', 'container.service_subscriber']; + foreach ($definitions as [$id, $definition]) { $decoratedService = $definition->getDecoratedService(); [$inner, $renamedId] = $decoratedService; @@ -89,8 +93,8 @@ public function process(ContainerBuilder $container) $decoratingTags = $decoratingDefinition->getTags(); $resetTags = []; - // container.service_locator and container.service_subscriber have special logic and they must not be transferred out to decorators - foreach (['container.service_locator', 'container.service_subscriber'] as $containerTag) { + // Behavior-describing tags must not be transferred out to decorators + foreach ($tagsToKeep as $containerTag) { if (isset($decoratingTags[$containerTag])) { $resetTags[$containerTag] = $decoratingTags[$containerTag]; unset($decoratingTags[$containerTag]); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php index 358b750f2a376..7935983ff5c2e 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php @@ -177,7 +177,7 @@ protected function processValue($value, $isRoot = false) */ private function isInlineableDefinition(string $id, Definition $definition): bool { - if ($definition->hasErrors() || $definition->isDeprecated() || $definition->isLazy() || $definition->isSynthetic()) { + if ($definition->hasErrors() || $definition->isDeprecated() || $definition->isLazy() || $definition->isSynthetic() || $definition->hasTag('container.do_not_inline')) { return false; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php index 4f01d33c4923d..ac4269753525c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -325,6 +325,34 @@ public function testProcessDoesNotSetLazyArgumentValuesAfterInlining() $this->assertSame('inline', (string) $values[0]); } + public function testDoNotInline() + { + $container = new ContainerBuilder(); + $container->register('decorated1', 'decorated1')->addTag('container.do_not_inline'); + $container->register('decorated2', 'decorated2')->addTag('container.do_not_inline'); + $container->setAlias('alias2', 'decorated2'); + + $container + ->register('s1', 's1') + ->setDecoratedService('decorated1') + ->setPublic(true) + ->setProperties(['inner' => new Reference('s1.inner')]); + + $container + ->register('s2', 's2') + ->setDecoratedService('alias2') + ->setPublic(true) + ->setProperties(['inner' => new Reference('s2.inner')]); + + $container->compile(); + + $this->assertFalse($container->hasAlias('alias2')); + $this->assertEquals(new Reference('decorated2'), $container->getDefinition('s2')->getProperties()['inner']); + $this->assertEquals(new Reference('s1.inner'), $container->getDefinition('s1')->getProperties()['inner']); + $this->assertSame('decorated2', $container->getDefinition('decorated2')->getClass()); + $this->assertSame('decorated1', $container->getDefinition('s1.inner')->getClass()); + } + protected function process(ContainerBuilder $container) { (new InlineServiceDefinitionsPass(new AnalyzeServiceReferencesPass()))->process($container); From c1ef4debf22c4a22e32e28f4dfc5a31b560b6c7b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 21 May 2022 15:41:46 +0200 Subject: [PATCH 38/48] [FrameworkBundle] fix tests --- .../Tests/Functional/Extension/TestDumpExtension.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php index 17738adf1b151..d8cef92850992 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Extension/TestDumpExtension.php @@ -18,7 +18,7 @@ class TestDumpExtension extends Extension implements ConfigurationInterface { - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('test_dump'); $treeBuilder->getRootNode() @@ -30,11 +30,11 @@ public function getConfigTreeBuilder() return $treeBuilder; } - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { } - public function getConfiguration(array $config, ContainerBuilder $container) + public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface { return $this; } From b0840e9d332532656963ba57df4767dff228e688 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 23 May 2022 12:31:37 +0200 Subject: [PATCH 39/48] Fix merge --- .../FrameworkBundle/Command/ConfigDumpReferenceCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php index 9a3c1b658483d..7a56ec5abed48 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php @@ -110,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($extension instanceof ConfigurationInterface) { $configuration = $extension; } else { - $configuration = $extension->getConfiguration([], $this->getContainerBuilder()); + $configuration = $extension->getConfiguration([], $this->getContainerBuilder($this->getApplication()->getKernel())); } $this->validateConfiguration($extension, $configuration); From 5611df1ea4ce610cc3af133e3aa3d02cdc19d1c9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 23 May 2022 13:43:43 +0200 Subject: [PATCH 40/48] Fix merge --- .../Bundle/FrameworkBundle/Command/AbstractConfigCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php index ad67fb4b4a818..f0d5a98148640 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AbstractConfigCommand.php @@ -98,7 +98,7 @@ protected function findExtension(string $name) } } - $container = $this->getContainerBuilder(); + $container = $this->getContainerBuilder($kernel); if ($container->hasExtension($name)) { return $container->getExtension($name); From 36d6516d81965b12d9092a7ecb258f94f6b94658 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Mon, 23 May 2022 23:42:43 +0200 Subject: [PATCH 41/48] Revert "bug #46125 [FrameworkBundle] Always add CacheCollectorPass (fancyweb)" This reverts commit 8b6f56e3805ab3231ffebfbe9648643a364af725, reversing changes made to fd1c94ba5676b9943e02a457166651a072b0018f. --- src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 1e76d527cd6b3..f5c52cf19749d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -157,12 +157,12 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new RegisterReverseContainerPass(true)); $container->addCompilerPass(new RegisterReverseContainerPass(false), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new SessionPass()); - $container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING); if ($container->getParameter('kernel.debug')) { $container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2); $container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255); + $container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING); } } From 1dbf3a607ede27b9b1f81647b31863afd41a0084 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 24 May 2022 09:53:05 +0200 Subject: [PATCH 42/48] [DoctrineBridge] Don't reinit managers when they are proxied as ghost objects --- src/Symfony/Bridge/Doctrine/ManagerRegistry.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php index 0ed055fec64b7..b001cfd933210 100644 --- a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php +++ b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\Doctrine; use Doctrine\Persistence\AbstractManagerRegistry; +use ProxyManager\Proxy\GhostObjectInterface; use ProxyManager\Proxy\LazyLoadingInterface; use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator; use Symfony\Component\DependencyInjection\Container; @@ -19,7 +20,7 @@ /** * References Doctrine connections and entity/document managers. * - * @author Lukas Kahwe Smith + * @author Lukas Kahwe Smith */ abstract class ManagerRegistry extends AbstractManagerRegistry { @@ -53,6 +54,9 @@ protected function resetService($name) if (!$manager instanceof LazyLoadingInterface) { throw new \LogicException('Resetting a non-lazy manager service is not supported. '.(interface_exists(LazyLoadingInterface::class) && class_exists(RuntimeInstantiator::class) ? sprintf('Declare the "%s" service as lazy.', $name) : 'Try running "composer require symfony/proxy-manager-bridge".')); } + if ($manager instanceof GhostObjectInterface) { + throw new \LogicException('Resetting a lazy-ghost-object manager service is not supported.'); + } $manager->setProxyInitializer(\Closure::bind( function (&$wrappedInstance, LazyLoadingInterface $manager) use ($name) { if (isset($this->normalizedIds[$normalizedId = strtolower($name)])) { // BC with DI v3.4 From 4cc3b3d5897e521e15cc0c612afafdcd7140085c Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 24 May 2022 16:08:07 +0200 Subject: [PATCH 43/48] [DependencyInjection] Fix "proxy" tag: resolve its parameters and pass it to child definitions --- .../Compiler/ResolveChildDefinitionsPass.php | 6 +++++ .../ResolveParameterPlaceHoldersPass.php | 5 ++++ .../ResolveChildDefinitionsPassTest.php | 25 +++++++++++++++++++ .../ResolveParameterPlaceHoldersPassTest.php | 14 +++++++++++ 4 files changed, 50 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php index 333480d66683c..de59dafd2151b 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php @@ -187,6 +187,12 @@ private function doResolveDefinition(ChildDefinition $definition): Definition // and it's not legal on an instanceof $def->setAutoconfigured($definition->isAutoconfigured()); + if (!$def->hasTag('proxy')) { + foreach ($parentDef->getTag('proxy') as $v) { + $def->addTag('proxy', $v); + } + } + return $def; } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php index 32eb6a3a76f3e..d31c54661c0b4 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php @@ -85,6 +85,11 @@ protected function processValue($value, $isRoot = false) if (isset($changes['file'])) { $value->setFile($this->bag->resolveValue($value->getFile())); } + $tags = $value->getTags(); + if (isset($tags['proxy'])) { + $tags['proxy'] = $this->bag->resolveValue($tags['proxy']); + $value->setTags($tags); + } } $value = parent::processValue($value, $isRoot); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php index 7a89feb9b7659..7293dd94b2936 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php @@ -118,6 +118,31 @@ public function testProcessDoesNotCopyTags() $this->assertEquals([], $def->getTags()); } + public function testProcessCopiesTagsProxy() + { + $container = new ContainerBuilder(); + + $container + ->register('parent') + ->addTag('proxy', ['a' => 'b']) + ; + + $container + ->setDefinition('child1', new ChildDefinition('parent')) + ; + $container + ->setDefinition('child2', (new ChildDefinition('parent'))->addTag('proxy', ['c' => 'd'])) + ; + + $this->process($container); + + $def = $container->getDefinition('child1'); + $this->assertSame(['proxy' => [['a' => 'b']]], $def->getTags()); + + $def = $container->getDefinition('child2'); + $this->assertSame(['proxy' => [['c' => 'd']]], $def->getTags()); + } + public function testProcessDoesNotCopyDecoratedService() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php index c586e72c2acbc..96c45205459df 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveParameterPlaceHoldersPassTest.php @@ -97,6 +97,20 @@ public function testParameterNotFoundExceptionsIsNotThrown() $this->assertCount(1, $definition->getErrors()); } + public function testOnlyProxyTagIsResolved() + { + $containerBuilder = new ContainerBuilder(); + $containerBuilder->setParameter('a_param', 'here_you_go'); + $definition = $containerBuilder->register('def'); + $definition->addTag('foo', ['bar' => '%a_param%']); + $definition->addTag('proxy', ['interface' => '%a_param%']); + + $pass = new ResolveParameterPlaceHoldersPass(true, false); + $pass->process($containerBuilder); + + $this->assertSame(['foo' => [['bar' => '%a_param%']], 'proxy' => [['interface' => 'here_you_go']]], $definition->getTags()); + } + private function createContainerBuilder(): ContainerBuilder { $containerBuilder = new ContainerBuilder(); From dc4bca83bf9a3de7b72d7d0a9d1b8dfb898c2739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Tue, 24 May 2022 21:09:44 +0200 Subject: [PATCH 44/48] [PropertyInfo] Fix resolution of partially docblock covered constructors --- .../Component/PropertyInfo/Extractor/PhpStanExtractor.php | 4 ++++ .../{PhpStanExtractorTest.php => PhpStanExtractorTestDoc.php} | 1 + 2 files changed, 5 insertions(+) rename src/Symfony/Component/PropertyInfo/Tests/Extractor/{PhpStanExtractorTest.php => PhpStanExtractorTestDoc.php} (99%) diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php index d00b81e5f17d0..52a4a78f2537f 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php @@ -239,6 +239,10 @@ private function getDocBlockFromProperty(string $class, string $property): ?arra $phpDocNode = $this->phpDocParser->parse($tokens); $tokens->consumeTokenType(Lexer::TOKEN_END); + if (self::MUTATOR === $source && !$this->filterDocBlockParams($phpDocNode, $property)) { + return null; + } + return [$phpDocNode, $source, $reflectionProperty->class]; } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTestDoc.php similarity index 99% rename from src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php rename to src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTestDoc.php index 9edea0725481a..f57721ca31bdb 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTestDoc.php @@ -449,6 +449,7 @@ public function php80TypesProvider() { return [ [Php80Dummy::class, 'promotedAndMutated', [new Type(Type::BUILTIN_TYPE_STRING)]], + [Php80Dummy::class, 'promoted', null], [Php80PromotedDummy::class, 'promoted', null], ]; } From 02b7b5208740889ec0016b52a5ce4e0057dd1905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 17 May 2022 22:50:08 +0200 Subject: [PATCH 45/48] [Console] Complete negatable options (Fish) --- .../Output/BashCompletionOutput.php | 3 ++ .../Output/FishCompletionOutput.php | 3 ++ .../Tests/Command/CompleteCommandTest.php | 4 +- .../Output/BashCompletionOutputTest.php | 33 ++++++++++++ .../Output/CompletionOutputTestCase.php | 51 +++++++++++++++++++ .../Output/FishCompletionOutputTest.php | 33 ++++++++++++ 6 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Component/Console/Tests/Completion/Output/BashCompletionOutputTest.php create mode 100644 src/Symfony/Component/Console/Tests/Completion/Output/CompletionOutputTestCase.php create mode 100644 src/Symfony/Component/Console/Tests/Completion/Output/FishCompletionOutputTest.php diff --git a/src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php b/src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php index 8d5ffa6b67d4b..c6f76eb8fbd40 100644 --- a/src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php +++ b/src/Symfony/Component/Console/Completion/Output/BashCompletionOutput.php @@ -24,6 +24,9 @@ public function write(CompletionSuggestions $suggestions, OutputInterface $outpu $values = $suggestions->getValueSuggestions(); foreach ($suggestions->getOptionSuggestions() as $option) { $values[] = '--'.$option->getName(); + if ($option->isNegatable()) { + $values[] = '--no-'.$option->getName(); + } } $output->writeln(implode("\n", $values)); } diff --git a/src/Symfony/Component/Console/Completion/Output/FishCompletionOutput.php b/src/Symfony/Component/Console/Completion/Output/FishCompletionOutput.php index 9b02f09aa8250..d2c414e487511 100644 --- a/src/Symfony/Component/Console/Completion/Output/FishCompletionOutput.php +++ b/src/Symfony/Component/Console/Completion/Output/FishCompletionOutput.php @@ -24,6 +24,9 @@ public function write(CompletionSuggestions $suggestions, OutputInterface $outpu $values = $suggestions->getValueSuggestions(); foreach ($suggestions->getOptionSuggestions() as $option) { $values[] = '--'.$option->getName(); + if ($option->isNegatable()) { + $values[] = '--no-'.$option->getName(); + } } $output->write(implode("\n", $values)); } diff --git a/src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php b/src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php index 102f490a4ff05..87c64504b499f 100644 --- a/src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CompleteCommandTest.php @@ -119,9 +119,9 @@ public function testCompleteCommandInputDefinition(array $input, array $suggesti public function provideCompleteCommandInputDefinitionInputs() { - yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']]; + yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']]; yield 'custom' => [['bin/console', 'hello'], ['Fabien', 'Robin', 'Wouter']]; - yield 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']]; + yield 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-ansi', '--no-interaction']]; yield 'custom-aliased' => [['bin/console', 'ahoy'], ['Fabien', 'Robin', 'Wouter']]; } diff --git a/src/Symfony/Component/Console/Tests/Completion/Output/BashCompletionOutputTest.php b/src/Symfony/Component/Console/Tests/Completion/Output/BashCompletionOutputTest.php new file mode 100644 index 0000000000000..84ec56accbbfd --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Completion/Output/BashCompletionOutputTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Completion\Output; + +use Symfony\Component\Console\Completion\Output\BashCompletionOutput; +use Symfony\Component\Console\Completion\Output\CompletionOutputInterface; + +class BashCompletionOutputTest extends CompletionOutputTestCase +{ + public function getCompletionOutput(): CompletionOutputInterface + { + return new BashCompletionOutput(); + } + + public function getExpectedOptionsOutput(): string + { + return "--option1\n--negatable\n--no-negatable".\PHP_EOL; + } + + public function getExpectedValuesOutput(): string + { + return "Green\nRed\nYellow".\PHP_EOL; + } +} diff --git a/src/Symfony/Component/Console/Tests/Completion/Output/CompletionOutputTestCase.php b/src/Symfony/Component/Console/Tests/Completion/Output/CompletionOutputTestCase.php new file mode 100644 index 0000000000000..c4551e5b67b70 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Completion/Output/CompletionOutputTestCase.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Completion\Output; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Completion\CompletionSuggestions; +use Symfony\Component\Console\Completion\Output\CompletionOutputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\StreamOutput; + +abstract class CompletionOutputTestCase extends TestCase +{ + abstract public function getCompletionOutput(): CompletionOutputInterface; + + abstract public function getExpectedOptionsOutput(): string; + + abstract public function getExpectedValuesOutput(): string; + + public function testOptionsOutput() + { + $options = [ + new InputOption('option1', 'o', InputOption::VALUE_NONE), + new InputOption('negatable', null, InputOption::VALUE_NEGATABLE), + ]; + $suggestions = new CompletionSuggestions(); + $suggestions->suggestOptions($options); + $stream = fopen('php://memory', 'rw+'); + $this->getCompletionOutput()->write($suggestions, new StreamOutput($stream)); + fseek($stream, 0); + $this->assertEquals($this->getExpectedOptionsOutput(), stream_get_contents($stream)); + } + + public function testValuesOutput() + { + $suggestions = new CompletionSuggestions(); + $suggestions->suggestValues(['Green', 'Red', 'Yellow']); + $stream = fopen('php://memory', 'rw+'); + $this->getCompletionOutput()->write($suggestions, new StreamOutput($stream)); + fseek($stream, 0); + $this->assertEquals($this->getExpectedValuesOutput(), stream_get_contents($stream)); + } +} diff --git a/src/Symfony/Component/Console/Tests/Completion/Output/FishCompletionOutputTest.php b/src/Symfony/Component/Console/Tests/Completion/Output/FishCompletionOutputTest.php new file mode 100644 index 0000000000000..2e615d04016ee --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Completion/Output/FishCompletionOutputTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Completion\Output; + +use Symfony\Component\Console\Completion\Output\CompletionOutputInterface; +use Symfony\Component\Console\Completion\Output\FishCompletionOutput; + +class FishCompletionOutputTest extends CompletionOutputTestCase +{ + public function getCompletionOutput(): CompletionOutputInterface + { + return new FishCompletionOutput(); + } + + public function getExpectedOptionsOutput(): string + { + return "--option1\n--negatable\n--no-negatable"; + } + + public function getExpectedValuesOutput(): string + { + return "Green\nRed\nYellow"; + } +} From a39c25cfbf98adcb4e7677f1c7be24bad231e307 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Wed, 25 May 2022 07:04:09 +0200 Subject: [PATCH 46/48] [ExpressionLanguage] Fix null-safe chaining --- .../ExpressionLanguage/Node/GetAttrNode.php | 28 ++++++++++++ .../Tests/ExpressionLanguageTest.php | 45 ++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php b/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php index edcec01374749..f5a14879528df 100644 --- a/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php +++ b/src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php @@ -24,6 +24,8 @@ class GetAttrNode extends Node public const METHOD_CALL = 2; public const ARRAY_CALL = 3; + private bool $isShortCircuited = false; + public function __construct(Node $node, Node $attribute, ArrayNode $arguments, int $type) { parent::__construct( @@ -70,9 +72,16 @@ public function evaluate(array $functions, array $values) switch ($this->attributes['type']) { case self::PROPERTY_CALL: $obj = $this->nodes['node']->evaluate($functions, $values); + if (null === $obj && $this->nodes['attribute']->isNullSafe) { + $this->isShortCircuited = true; + + return null; + } + if (null === $obj && $this->isShortCircuited()) { return null; } + if (!\is_object($obj)) { throw new \RuntimeException(sprintf('Unable to get property "%s" of non-object "%s".', $this->nodes['attribute']->dump(), $this->nodes['node']->dump())); } @@ -83,9 +92,16 @@ public function evaluate(array $functions, array $values) case self::METHOD_CALL: $obj = $this->nodes['node']->evaluate($functions, $values); + if (null === $obj && $this->nodes['attribute']->isNullSafe) { + $this->isShortCircuited = true; + + return null; + } + if (null === $obj && $this->isShortCircuited()) { return null; } + if (!\is_object($obj)) { throw new \RuntimeException(sprintf('Unable to call method "%s" of non-object "%s".', $this->nodes['attribute']->dump(), $this->nodes['node']->dump())); } @@ -97,6 +113,11 @@ public function evaluate(array $functions, array $values) case self::ARRAY_CALL: $array = $this->nodes['node']->evaluate($functions, $values); + + if (null === $array && $this->isShortCircuited()) { + return null; + } + if (!\is_array($array) && !$array instanceof \ArrayAccess) { throw new \RuntimeException(sprintf('Unable to get an item of non-array "%s".', $this->nodes['node']->dump())); } @@ -105,6 +126,13 @@ public function evaluate(array $functions, array $values) } } + private function isShortCircuited(): bool + { + return $this->isShortCircuited + || ($this->nodes['node'] instanceof self && $this->nodes['node']->isShortCircuited()) + ; + } + public function toArray() { switch ($this->attributes['type']) { diff --git a/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php b/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php index 1f9770972f5e6..2c66d52927e58 100644 --- a/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php +++ b/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php @@ -249,13 +249,13 @@ public function testNullSafeEvaluate($expression, $foo) /** * @dataProvider provideNullSafe */ - public function testNullsafeCompile($expression, $foo) + public function testNullSafeCompile($expression, $foo) { $expressionLanguage = new ExpressionLanguage(); $this->assertNull(eval(sprintf('return %s;', $expressionLanguage->compile($expression, ['foo' => 'foo'])))); } - public function provideNullsafe() + public function provideNullSafe() { $foo = new class() extends \stdClass { public function bar() @@ -272,6 +272,47 @@ public function bar() yield ['foo["bar"]?.baz()', ['bar' => null]]; yield ['foo.bar()?.baz', $foo]; yield ['foo.bar()?.baz()', $foo]; + + yield ['foo?.bar.baz', null]; + yield ['foo?.bar["baz"]', null]; + yield ['foo?.bar["baz"]["qux"]', null]; + yield ['foo?.bar["baz"]["qux"].quux', null]; + yield ['foo?.bar["baz"]["qux"].quux()', null]; + yield ['foo?.bar().baz', null]; + yield ['foo?.bar()["baz"]', null]; + yield ['foo?.bar()["baz"]["qux"]', null]; + yield ['foo?.bar()["baz"]["qux"].quux', null]; + yield ['foo?.bar()["baz"]["qux"].quux()', null]; + } + + /** + * @dataProvider provideInvalidNullSafe + */ + public function testNullSafeEvaluateFails($expression, $foo, $message) + { + $expressionLanguage = new ExpressionLanguage(); + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage($message); + $expressionLanguage->evaluate($expression, ['foo' => $foo]); + } + + /** + * @dataProvider provideInvalidNullSafe + */ + public function testNullSafeCompileFails($expression, $foo) + { + $expressionLanguage = new ExpressionLanguage(); + + $this->expectWarning(); + eval(sprintf('return %s;', $expressionLanguage->compile($expression, ['foo' => 'foo']))); + } + + public function provideInvalidNullSafe() + { + yield ['foo?.bar.baz', (object) ['bar' => null], 'Unable to get property "baz" of non-object "foo.bar".']; + yield ['foo?.bar["baz"]', (object) ['bar' => null], 'Unable to get an item of non-array "foo.bar".']; + yield ['foo?.bar["baz"].qux.quux', (object) ['bar' => ['baz' => null]], 'Unable to get property "qux" of non-object "foo.bar["baz"]".']; } /** From bcd3899a6cb28cd1a8e16504b253e624026e74c4 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 27 May 2022 09:20:57 +0200 Subject: [PATCH 47/48] Update CHANGELOG for 6.1.0 --- CHANGELOG-6.1.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/CHANGELOG-6.1.md b/CHANGELOG-6.1.md index 88b3cc9960d82..861bc8ed110f7 100644 --- a/CHANGELOG-6.1.md +++ b/CHANGELOG-6.1.md @@ -7,6 +7,38 @@ in 6.1 minor versions. To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v6.1.0...v6.1.1 +* 6.1.0 (2022-05-27) + + * bug #46453 [PropertyInfo] Fix resolution of partially docblock covered constructors (ostrolucky) + * bug #46454 [ExpressionLanguage] Fix null-safe chaining (HypeMC) + * bug #46386 [Console]  Fix missing negative variation of negatable options in shell completion (GromNaN) + * bug #46387 [Console] Complete negatable options (Fish) (GromNaN) + * bug #46448 [DependencyInjection] Fix "proxy" tag: resolve its parameters and pass it to child definitions (nicolas-grekas) + * bug #46442 [FrameworkBundle] Revert "bug #46125 Always add CacheCollectorPass (fancyweb)" (chalasr) + * bug #46443 [DoctrineBridge] Don't reinit managers when they are proxied as ghost objects (nicolas-grekas) + * bug #46427 [FrameworkBundle] fix wiring of annotations.cached_reader (nicolas-grekas) + * bug #46425 [DependencyInjection] Ignore unused bindings defined by attribute (nicolas-grekas) + * bug #46434 [FrameworkBundle] Fix BC break in abstract config commands (yceruto) + * bug #46424 [Form] do not accept array input when a form is not multiple (xabbuh) + * bug #46367 [Mime] Throw exception when body in Email attach method is not ok (alamirault) + * bug #46421 [VarDumper][VarExporter] Deal with DatePeriod->include_end_date on PHP 8.2 (nicolas-grekas) + * bug #46401 [Cache] Throw when "redis_sentinel" is used with a non-Predis "class" option (buffcode) + * bug #46414 Bootstrap 4 fieldset for row errors (konradkozaczenko) + * bug #46412 [FrameworkBundle] Fix dumping extension config without bundle (yceruto) + * bug #46385 [HttpKernel] New bundle path convention when `AbstractBundle` is used (yceruto) + * bug #46382 [HttpClient] Honor "max_duration" when replacing requests with async decorators (nicolas-grekas) + * bug #46407 [Filesystem] Safeguard (sym)link calls (derrabus) + * bug #46098 [Form] Fix same choice loader with different choice values (HeahDude) + * bug #46380 [HttpClient] Add missing HttpOptions::setMaxDuration() (nicolas-grekas) + * bug #46377 [HttpKernel] Fix missing null type in `ErrorListener::__construct()` (chalasr) + * bug #46249 [HttpFoundation] [Session] Regenerate invalid session id (peter17) + * bug #46373 [HtmlSanitizer] Fix default config service definition (wouterj) + * bug #46328 [Config] Allow scalar configuration in PHP Configuration (jderusse, HypeMC) + * bug #46366 [Mime] Add null check for EmailHeaderSame (magikid) + * bug #46361 [PropertyInfo] Ignore empty doc-block for promoted properties in PhpStanExtractor (BoShurik) + * bug #46364 [Config] Fix looking for single files in phars with GlobResource (nicolas-grekas) + * bug #46365 [HttpKernel] Revert "bug #46327 Allow ErrorHandler ^5.0 to be used" (nicolas-grekas) + * 6.1.0-RC1 (2022-05-14) * feature #46335 [Form][FrameworkBundle][TwigBundle] Add Twig filter, form-type extension and improve service definitions for HtmlSanitizer (nicolas-grekas) From 756eed12af10f28bd6644777df7ec0104b3fad74 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 27 May 2022 09:21:03 +0200 Subject: [PATCH 48/48] Update VERSION for 6.1.0 --- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index aafc62dbb01f9..37a758c7cfaf1 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -78,12 +78,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.1.0-DEV'; + public const VERSION = '6.1.0'; public const VERSION_ID = 60100; public const MAJOR_VERSION = 6; public const MINOR_VERSION = 1; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '01/2023'; public const END_OF_LIFE = '01/2023';