Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f98846

Browse files
bug #32604 Properly handle optional tag attributes for !tagged_iterator (apfelbox)
This PR was merged into the 4.3 branch. Discussion ---------- Properly handle optional tag attributes for !tagged_iterator | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? |no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #32603 | License | MIT | Doc PR | — Properly handles all optional array keys when using `!tagged_iterator` in YAML service definitions. This fixes a regression and adds a test case preventing it from coming up again Commits ------- d1c6580 Properly handle optional tag attributes for !tagged_iterator
2 parents 4d7f072 + d1c6580 commit 3f98846

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ private function resolveServices($value, $file, $isParameter = false)
736736
throw new InvalidArgumentException(sprintf('"!%s" tag contains unsupported key "%s"; supported ones are "tag", "index_by" and "default_index_method".', $value->getTag(), implode('"", "', $diff)));
737737
}
738738

739-
$argument = new TaggedIteratorArgument($argument['tag'], $argument['index_by'], $argument['default_index_method'] ?? null, $forLocator);
739+
$argument = new TaggedIteratorArgument($argument['tag'], $argument['index_by'] ?? null, $argument['default_index_method'] ?? null, $forLocator);
740740

741741
if ($forLocator) {
742742
$argument = new ServiceLocatorArgument($argument);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
iterator_service:
3+
class: FooClass
4+
arguments: [!tagged {tag: test.tag}]

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,4 +852,18 @@ public function testOverriddenDefaultsBindings()
852852

853853
$this->assertSame('overridden', $container->get('bar')->quz);
854854
}
855+
856+
/**
857+
* When creating a tagged iterator using the array syntax, all optional parameters should be properly handled.
858+
*/
859+
public function testDefaultValueOfTagged()
860+
{
861+
$container = new ContainerBuilder();
862+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
863+
$loader->load('tagged_iterator_optional.yml');
864+
865+
$iteratorArgument = $container->getDefinition('iterator_service')->getArgument(0);
866+
$this->assertInstanceOf(TaggedIteratorArgument::class, $iteratorArgument);
867+
$this->assertNull($iteratorArgument->getIndexAttribute());
868+
}
855869
}

0 commit comments

Comments
 (0)