From 0fe09bf25cb64deef73e8eab7be89f9401d2f5b8 Mon Sep 17 00:00:00 2001 From: Farhad Safarov Date: Thu, 6 Jun 2024 00:20:57 +0300 Subject: [PATCH] Handle Symfony 7.1 containerxml (#344) fixes https://github.com/psalm/psalm-plugin-symfony/issues/336 --- src/Symfony/ContainerMeta.php | 12 +++++++++--- tests/acceptance/container.xml | 11 +++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Symfony/ContainerMeta.php b/src/Symfony/ContainerMeta.php index 433c021..f64347b 100644 --- a/src/Symfony/ContainerMeta.php +++ b/src/Symfony/ContainerMeta.php @@ -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; } diff --git a/tests/acceptance/container.xml b/tests/acceptance/container.xml index 7b34076..3d20c51 100644 --- a/tests/acceptance/container.xml +++ b/tests/acceptance/container.xml @@ -46,7 +46,7 @@ - + @@ -66,7 +66,7 @@ - + @@ -87,5 +87,12 @@ + + + + kernel::registerContainerConfiguration() + + +