Skip to content

Commit

Permalink
bug #34732 [DependencyInjection][Xml] Fix the attribute 'tag' is not …
Browse files Browse the repository at this point in the history
…allowed in 'bind' tag (tienvx)

This PR was merged into the 4.4 branch.

Discussion
----------

[DependencyInjection][Xml] Fix the attribute 'tag' is not allowed in 'bind' tag

| Q             | A
| ------------- | ---
| Branch?       | 4.4 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | N/A <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs/pull/12741 <!-- required for new features -->

Add test case for https://symfony.com/blog/new-in-symfony-4-4-dependency-injection-improvements-part-1#allow-binding-tagged-services and fix a bug with attribute 'tag' is not allowed

Commits
-------

e38f7d4 [DependencyInjection][Xml] Fix the attribute 'tag' is not allowed in 'bind' tag
  • Loading branch information
fabpot committed Nov 30, 2019
2 parents 9b658ed + e38f7d4 commit 28e1d1e
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 1 deletion.
Expand Up @@ -222,6 +222,7 @@
<xsd:attribute name="key" type="xsd:string" use="required" />
<xsd:attribute name="on-invalid" type="invalid_sequence" />
<xsd:attribute name="method" type="xsd:string" />
<xsd:attribute name="tag" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="argument" mixed="true">
Expand Down
Expand Up @@ -15,7 +15,7 @@ class Bar implements BarInterface
{
public $quz;

public function __construct($quz = null, \NonExistent $nonExistent = null, BarInterface $decorated = null, array $foo = [])
public function __construct($quz = null, \NonExistent $nonExistent = null, BarInterface $decorated = null, array $foo = [], iterable $baz = [])
{
$this->quz = $quz;
}
Expand Down
Expand Up @@ -12,6 +12,7 @@
<bind key="$foo" type="collection">
<bind>null</bind>
</bind>
<bind key="iterable $baz" type="tagged_iterator" tag="bar"/>
</service>

<service id="Symfony\Component\DependencyInjection\Tests\Fixtures\Bar">
Expand Down
Expand Up @@ -12,6 +12,7 @@ services:
bind:
Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface: '@Symfony\Component\DependencyInjection\Tests\Fixtures\Bar'
$foo: [ ~ ]
iterable $baz: !tagged_iterator bar

Symfony\Component\DependencyInjection\Tests\Fixtures\Bar:
factory: [ ~, 'create' ]
Expand Up @@ -879,12 +879,14 @@ public function testBindings()
'$foo' => [null],
'$quz' => 'quz',
'$factory' => 'factory',
'iterable $baz' => new TaggedIteratorArgument('bar'),
], array_map(function (BoundArgument $v) { return $v->getValues()[0]; }, $definition->getBindings()));
$this->assertEquals([
'quz',
null,
new Reference(Bar::class),
[null],
new TaggedIteratorArgument('bar'),
], $definition->getArguments());

$definition = $container->getDefinition(Bar::class);
Expand Down
Expand Up @@ -801,12 +801,14 @@ public function testBindings()
'$foo' => [null],
'$quz' => 'quz',
'$factory' => 'factory',
'iterable $baz' => new TaggedIteratorArgument('bar'),
], array_map(function (BoundArgument $v) { return $v->getValues()[0]; }, $definition->getBindings()));
$this->assertEquals([
'quz',
null,
new Reference(Bar::class),
[null],
new TaggedIteratorArgument('bar'),
], $definition->getArguments());

$definition = $container->getDefinition(Bar::class);
Expand Down

0 comments on commit 28e1d1e

Please sign in to comment.