Skip to content

Commit

Permalink
Support for alias to inlined service
Browse files Browse the repository at this point in the history
  • Loading branch information
b-viguier authored and ondrejmirtes committed May 30, 2024
1 parent d530cfe commit 2c3d666
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Symfony/XmlServiceMapFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public function create(): ServiceMap
}

$service = new Service(
strpos((string) $attrs->id, '.') === 0 ? substr((string) $attrs->id, 1) : (string) $attrs->id,
$this->cleanServiceId((string) $attrs->id),
isset($attrs->class) ? (string) $attrs->class : null,
isset($attrs->public) && (string) $attrs->public === 'true',
isset($attrs->synthetic) && (string) $attrs->synthetic === 'true',
isset($attrs->alias) ? (string) $attrs->alias : null
isset($attrs->alias) ? $this->cleanServiceId((string) $attrs->alias) : null
);

if ($service->getAlias() !== null) {
Expand All @@ -79,4 +79,9 @@ public function create(): ServiceMap
return new DefaultServiceMap($services);
}

private function cleanServiceId(string $id): string
{
return strpos($id, '.') === 0 ? substr($id, 1) : $id;
}

}
11 changes: 11 additions & 0 deletions tests/Symfony/DefaultServiceMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ static function (?Service $service): void {
self::assertSame('withClass', $service->getAlias());
},
];
yield [
'aliasForInlined',
static function (?Service $service): void {
self::assertNotNull($service);
self::assertSame('aliasForInlined', $service->getId());
self::assertNull($service->getClass());
self::assertFalse($service->isPublic());
self::assertFalse($service->isSynthetic());
self::assertSame('inlined', $service->getAlias());
},
];
}

}
2 changes: 2 additions & 0 deletions tests/Symfony/container.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
<service id="public" class="Foo" public="true"></service>
<service id="synthetic" class="Foo" synthetic="true"></service>
<service id="alias" class="Bar" alias="withClass"></service>
<service id=".inlined"></service>
<service id="aliasForInlined" alias=".inlined"></service>
</services>
</container>

0 comments on commit 2c3d666

Please sign in to comment.