Skip to content

Commit f4b79cc

Browse files
committed
[TASK] Take container.excluded tag into account
1 parent 1753adb commit f4b79cc

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/Service/XmlServiceMapFactory.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public function create(): ServiceMap
4343
continue;
4444
}
4545

46+
$tags = $this->createTags($def);
47+
48+
if (in_array('container.excluded', $tags, true)) {
49+
continue;
50+
}
51+
4652
$serviceDefinition = new ServiceDefinition(
4753
strpos((string) $attrs->id, '.') === 0 ? substr((string) $attrs->id, 1) : (string) $attrs->id,
4854
isset($attrs->class) ? (string) $attrs->class : null,
@@ -75,4 +81,26 @@ public function create(): ServiceMap
7581
return new DefaultServiceMap($serviceDefinitions);
7682
}
7783

84+
/**
85+
* @return string[]
86+
*/
87+
private function createTags(?SimpleXMLElement $def): array
88+
{
89+
if (!isset($def->tag)) {
90+
return [];
91+
}
92+
93+
$tagNames = [];
94+
95+
foreach ($def->tag as $tag) {
96+
$attributes = $tag->attributes();
97+
if (!isset($attributes->name)) {
98+
continue;
99+
}
100+
$tagNames[] = (string) $attributes->name;
101+
}
102+
103+
return $tagNames;
104+
}
105+
78106
}

tests/Unit/Fixtures/container.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
<service id="publicNotTrue" class="Foo" public="false"></service>
99
<service id="public" class="Foo" public="true"></service>
1010
<service id="synthetic" class="Foo" synthetic="true"></service>
11-
<service id="alias" class="Bar" alias="withClass"></service>
11+
<service id="alias" class="Bar" alias="withClass">
12+
<tag name="event.listener"/>
13+
<tag name="foo"/>
14+
</service>
1215
<service id="private" class="Foo" public="false"></service>
16+
<service id="excluded" class="Foo" public="false">
17+
<tag name="container.excluded"/>
18+
</service>
1319
</services>
1420
</container>

tests/Unit/Service/XmlServiceMapFactoryTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public function testThatServiceDefinitionsAreConstructedSuccessfully(): void
3838

3939
$serviceDefinition = $serviceMap->getServiceDefinitionById('public');
4040
self::assertNotNull($serviceDefinition);
41+
42+
$serviceDefinitionExcluded = $serviceMap->getServiceDefinitionById('excluded');
43+
self::assertNull($serviceDefinitionExcluded);
4144
}
4245

4346
private function createServiceMap(?string $containerXmlPath): ServiceMap

0 commit comments

Comments
 (0)