Skip to content

Commit

Permalink
Handle Symfony 7.1 containerxml (#344)
Browse files Browse the repository at this point in the history
fixes #336
  • Loading branch information
seferov authored Jun 5, 2024
1 parent 5716321 commit 0fe09bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/Symfony/ContainerMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ private function init(array $containerXmlPaths): void
$xml->load($containerXmlPath);

foreach ($this->container->getDefinitions() as $definition) {
if ($definition->hasTag('container.service_locator')) {
continue;
}

$definitionFactory = $definition->getFactory();
if ($definition->hasTag('container.service_locator_context') && is_array($definitionFactory)) {
/** @var Reference $reference */
$reference = $definitionFactory[0];
$id = $definition->getTag('container.service_locator_context')[0]['id'];
$this->classLocators[$this->container->getDefinition($id)->getClass() ?? $id] = (string) $reference;
} elseif ($definition->hasTag('container.service_locator')) {
continue;
try {
$this->classLocators[$this->container->getDefinition($id)->getClass() ?? $id] = (string) $reference;
} catch (ServiceNotFoundException) {
continue;
}
} elseif (null !== $className = $definition->getClass()) {
$this->classNames[] = $className;
}
Expand Down
11 changes: 9 additions & 2 deletions tests/acceptance/container.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<service id="dummy_private_service" class="Psalm\SymfonyPsalmPlugin\Tests\Fixture\DummyPrivateService" public="false"/>
<service id="public_service_wo_public_attr" class="Foo\Bar"/>
<service id="wronglyNamedService" class="Foo\Bar" public="true" />
<!-- service subscriber 1 example -->
<!-- service locator example 1 -->
<service id="App\Controller\DummyController" class="App\Controller\DummyController">
<tag name="container.service_subscriber"/>
<argument type="service" id=".service_locator.123xyz.App\Controller\DummyController"/>
Expand All @@ -66,7 +66,7 @@
<argument type="service" id="service_container"/>
<factory service=".service_locator.123xyz" method="withContext"/>
</service>
<!-- service subscriber 2 example -->
<!-- service locator example 2 -->
<service id="service_subscriber_2" class="App\SomeClass" autowire="true" autoconfigure="true">
<tag name="container.service_subscriber"/>
<argument type="service" id=".service_locator.456xyz.service_subscriber_2"/>
Expand All @@ -87,5 +87,12 @@
<argument key="1234" type="service" id="Psalm\SymfonyPsalmPlugin\Tests\Fixture\DummyPrivateService"/>
</argument>
</service>
<!-- service locator example 3 -->
<service id=".service_locator.890xyz.kernel::registerContainerConfiguration()" class="Symfony\Component\DependencyInjection\ServiceLocator">
<tag name="container.service_locator_context" id="kernel::registerContainerConfiguration()"/>
<argument>kernel::registerContainerConfiguration()</argument>
<argument type="service" id="service_container"/>
<factory service=".service_locator.890xyz" method="withContext"/>
</service>
</services>
</container>

0 comments on commit 0fe09bf

Please sign in to comment.