Skip to content

Commit

Permalink
bug #32604 Properly handle optional tag attributes for !tagged_iterat…
Browse files Browse the repository at this point in the history
…or (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
  • Loading branch information
nicolas-grekas committed Jul 18, 2019
2 parents 4d7f072 + d1c6580 commit 3f98846
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Expand Up @@ -736,7 +736,7 @@ private function resolveServices($value, $file, $isParameter = false)
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);
Expand Down
@@ -0,0 +1,4 @@
services:
iterator_service:
class: FooClass
arguments: [!tagged {tag: test.tag}]
Expand Up @@ -852,4 +852,18 @@ public function testOverriddenDefaultsBindings()

$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());
}
}

0 comments on commit 3f98846

Please sign in to comment.