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
-------

d1c6580192 Properly handle optional tag attributes for !tagged_iterator
This commit is contained in:
Nicolas Grekas 2019-07-18 22:37:28 +02:00
commit 3f988461d5
3 changed files with 19 additions and 1 deletions

View File

@ -736,7 +736,7 @@ class YamlFileLoader extends FileLoader
throw new InvalidArgumentException(sprintf('"!%s" tag contains unsupported key "%s"; supported ones are "tag", "index_by" and "default_index_method".', $value->getTag(), implode('"", "', $diff)));
}
$argument = new TaggedIteratorArgument($argument['tag'], $argument['index_by'], $argument['default_index_method'] ?? null, $forLocator);
$argument = new TaggedIteratorArgument($argument['tag'], $argument['index_by'] ?? null, $argument['default_index_method'] ?? null, $forLocator);
if ($forLocator) {
$argument = new ServiceLocatorArgument($argument);

View File

@ -0,0 +1,4 @@
services:
iterator_service:
class: FooClass
arguments: [!tagged {tag: test.tag}]

View File

@ -852,4 +852,18 @@ class YamlFileLoaderTest extends TestCase
$this->assertSame('overridden', $container->get('bar')->quz);
}
/**
* When creating a tagged iterator using the array syntax, all optional parameters should be properly handled.
*/
public function testDefaultValueOfTagged()
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('tagged_iterator_optional.yml');
$iteratorArgument = $container->getDefinition('iterator_service')->getArgument(0);
$this->assertInstanceOf(TaggedIteratorArgument::class, $iteratorArgument);
$this->assertNull($iteratorArgument->getIndexAttribute());
}
}