Skip to content

Commit

Permalink
bug #50351 [DependencyInjection] Add excludeSelf option to dumpers …
Browse files Browse the repository at this point in the history
…(HypeMC)

This PR was merged into the 6.3 branch.

Discussion
----------

[DependencyInjection] Add `excludeSelf` option to dumpers

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Followup to #48685.

It seems that the `excludeSelf` option was not added to the dumpers or configuration functions. I don't think this was done intentionally, but was an oversight.

Commits
-------

09c7581 [DependencyInjection] Add exclude-self option to dumpers
  • Loading branch information
nicolas-grekas committed May 18, 2023
2 parents 825fd03 + 09c7581 commit 3d6e0bd
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ private function convertParameters(array $parameters, string $type, \DOMElement
}
}
}
if (!$tag->excludeSelf()) {
$element->setAttribute('exclude-self', 'false');
}
} elseif ($value instanceof IteratorArgument) {
$element->setAttribute('type', 'iterator');
$this->convertParameters($value->getValues(), $type, $element, 'key');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ private function dumpValue(mixed $value): mixed
}
$content['exclude'] = 1 === \count($excludes) ? $excludes[0] : $excludes;
}
if (!$tag->excludeSelf()) {
$content['exclude_self'] = false;
}

return new TaggedValue($value instanceof TaggedIteratorArgument ? 'tagged_iterator' : 'tagged_locator', $content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,17 @@ function iterator(array $values): IteratorArgument
/**
* Creates a lazy iterator by tag name.
*/
function tagged_iterator(string $tag, string $indexAttribute = null, string $defaultIndexMethod = null, string $defaultPriorityMethod = null, string|array $exclude = []): TaggedIteratorArgument
function tagged_iterator(string $tag, string $indexAttribute = null, string $defaultIndexMethod = null, string $defaultPriorityMethod = null, string|array $exclude = [], bool $excludeSelf = true): TaggedIteratorArgument
{
return new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, false, $defaultPriorityMethod, (array) $exclude);
return new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, false, $defaultPriorityMethod, (array) $exclude, $excludeSelf);
}

/**
* Creates a service locator by tag name.
*/
function tagged_locator(string $tag, string $indexAttribute = null, string $defaultIndexMethod = null, string $defaultPriorityMethod = null, string|array $exclude = []): ServiceLocatorArgument
function tagged_locator(string $tag, string $indexAttribute = null, string $defaultIndexMethod = null, string $defaultPriorityMethod = null, string|array $exclude = [], bool $excludeSelf = true): ServiceLocatorArgument
{
return new ServiceLocatorArgument(new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, true, $defaultPriorityMethod, (array) $exclude));
return new ServiceLocatorArgument(new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, true, $defaultPriorityMethod, (array) $exclude, $excludeSelf));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function testTaggedArguments()
{
$taggedIterator = new TaggedIteratorArgument('foo_tag', 'barfoo', 'foobar', false, 'getPriority');
$taggedIterator2 = new TaggedIteratorArgument('foo_tag', null, null, false, null, ['baz']);
$taggedIterator3 = new TaggedIteratorArgument('foo_tag', null, null, false, null, ['baz', 'qux']);
$taggedIterator3 = new TaggedIteratorArgument('foo_tag', null, null, false, null, ['baz', 'qux'], false);

$container = new ContainerBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testTaggedArguments()
{
$taggedIterator = new TaggedIteratorArgument('foo', 'barfoo', 'foobar', false, 'getPriority');
$taggedIterator2 = new TaggedIteratorArgument('foo', null, null, false, null, ['baz']);
$taggedIterator3 = new TaggedIteratorArgument('foo', null, null, false, null, ['baz', 'qux']);
$taggedIterator3 = new TaggedIteratorArgument('foo', null, null, false, null, ['baz', 'qux'], false);

$container = new ContainerBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<argument type="tagged_iterator" tag="foo_tag" exclude="baz"/>
</service>
<service id="foo3_tagged_iterator" class="Bar" public="true">
<argument type="tagged_iterator" tag="foo_tag">
<argument type="tagged_iterator" tag="foo_tag" exclude-self="false">
<exclude>baz</exclude>
<exclude>qux</exclude>
</argument>
Expand All @@ -30,7 +30,7 @@
<argument type="tagged_locator" tag="foo_tag" exclude="baz"/>
</service>
<service id="foo3_tagged_locator" class="Bar" public="true">
<argument type="tagged_locator" tag="foo_tag">
<argument type="tagged_locator" tag="foo_tag" exclude-self="false">
<exclude>baz</exclude>
<exclude>qux</exclude>
</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
arguments: [!tagged_iterator { tag: foo, exclude: baz }]
foo3_service_tagged_iterator:
class: Bar
arguments: [!tagged_iterator { tag: foo, exclude: [baz, qux] }]
arguments: [!tagged_iterator { tag: foo, exclude: [baz, qux], exclude_self: false }]
foo_service_tagged_locator:
class: Bar
arguments: [!tagged_locator { tag: foo, index_by: barfoo, default_index_method: foobar, default_priority_method: getPriority }]
Expand All @@ -33,7 +33,7 @@ services:
arguments: [!tagged_locator { tag: foo, exclude: baz }]
foo3_service_tagged_locator:
class: Bar
arguments: [!tagged_locator { tag: foo, exclude: [baz, qux] }]
arguments: [!tagged_locator { tag: foo, exclude: [baz, qux], exclude_self: false }]
bar_service_tagged_locator:
class: Bar
arguments: [!tagged_locator foo]
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,14 @@ public function testParseTaggedArgumentsWithIndexBy()
$this->assertEquals($taggedIterator, $container->getDefinition('foo_tagged_iterator')->getArgument(0));
$taggedIterator2 = new TaggedIteratorArgument('foo_tag', null, null, false, null, ['baz']);
$this->assertEquals($taggedIterator2, $container->getDefinition('foo2_tagged_iterator')->getArgument(0));
$taggedIterator3 = new TaggedIteratorArgument('foo_tag', null, null, false, null, ['baz', 'qux']);
$taggedIterator3 = new TaggedIteratorArgument('foo_tag', null, null, false, null, ['baz', 'qux'], false);
$this->assertEquals($taggedIterator3, $container->getDefinition('foo3_tagged_iterator')->getArgument(0));

$taggedIterator = new TaggedIteratorArgument('foo_tag', 'barfoo', 'foobar', true, 'getPriority');
$this->assertEquals(new ServiceLocatorArgument($taggedIterator), $container->getDefinition('foo_tagged_locator')->getArgument(0));
$taggedIterator2 = new TaggedIteratorArgument('foo_tag', 'foo_tag', 'getDefaultFooTagName', true, 'getDefaultFooTagPriority', ['baz']);
$this->assertEquals(new ServiceLocatorArgument($taggedIterator2), $container->getDefinition('foo2_tagged_locator')->getArgument(0));
$taggedIterator3 = new TaggedIteratorArgument('foo_tag', 'foo_tag', 'getDefaultFooTagName', true, 'getDefaultFooTagPriority', ['baz', 'qux']);
$taggedIterator3 = new TaggedIteratorArgument('foo_tag', 'foo_tag', 'getDefaultFooTagName', true, 'getDefaultFooTagPriority', ['baz', 'qux'], false);
$this->assertEquals(new ServiceLocatorArgument($taggedIterator3), $container->getDefinition('foo3_tagged_locator')->getArgument(0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,14 @@ public function testTaggedArgumentsWithIndex()
$this->assertEquals($taggedIterator, $container->getDefinition('foo_service_tagged_iterator')->getArgument(0));
$taggedIterator2 = new TaggedIteratorArgument('foo', null, null, false, null, ['baz']);
$this->assertEquals($taggedIterator2, $container->getDefinition('foo2_service_tagged_iterator')->getArgument(0));
$taggedIterator3 = new TaggedIteratorArgument('foo', null, null, false, null, ['baz', 'qux']);
$taggedIterator3 = new TaggedIteratorArgument('foo', null, null, false, null, ['baz', 'qux'], false);
$this->assertEquals($taggedIterator3, $container->getDefinition('foo3_service_tagged_iterator')->getArgument(0));

$taggedIterator = new TaggedIteratorArgument('foo', 'barfoo', 'foobar', true, 'getPriority');
$this->assertEquals(new ServiceLocatorArgument($taggedIterator), $container->getDefinition('foo_service_tagged_locator')->getArgument(0));
$taggedIterator2 = new TaggedIteratorArgument('foo', 'foo', 'getDefaultFooName', true, 'getDefaultFooPriority', ['baz']);
$this->assertEquals(new ServiceLocatorArgument($taggedIterator2), $container->getDefinition('foo2_service_tagged_locator')->getArgument(0));
$taggedIterator3 = new TaggedIteratorArgument('foo', 'foo', 'getDefaultFooName', true, 'getDefaultFooPriority', ['baz', 'qux']);
$taggedIterator3 = new TaggedIteratorArgument('foo', 'foo', 'getDefaultFooName', true, 'getDefaultFooPriority', ['baz', 'qux'], false);
$this->assertEquals(new ServiceLocatorArgument($taggedIterator3), $container->getDefinition('foo3_service_tagged_locator')->getArgument(0));

$taggedIterator = new TaggedIteratorArgument('foo', null, null, true);
Expand Down

0 comments on commit 3d6e0bd

Please sign in to comment.