Description
Symfony version(s) affected
6.2.0
Description
After update to Symfony 6.2, the new changes to support the array tag attributes introduced in #47364 throw an exception when it load a service tag with the name in the inner content of the tag.
How to reproduce
- Create a new project with
symfony/dependency-injection
andsymfony/config
dependencies. - Create a
index.php
file with the following content:
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
$containerBuilder = new ContainerBuilder();
$loader = new XmlFileLoader($containerBuilder, new FileLocator(__DIR__));
$loader->load('services.xml');
- Generate a
service.xml
with a service description with a tag, as the following.
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services">
<services>
<service id="dummy_service" class="App\Service\DummyService">
<tag>dummy_tag</tag>
</service>
</services>
</container>
- Try to run the
index.php
script.
Possible Solution
It looks like that in the XmlFileLoader tries to extract the tagName incorrectly, because the $tag->hasChildNodes()
return a boolean, and not an string, and when tries to extract the nodeValue
, it extracts the attribute name instead, causing the error.
symfony/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
Lines 339 to 341 in 3444c1e
I think that with the following code, that tries to extract the nodeValue and if it is not possible tries to get the attribute name from the XML tag, should solve the error.
if ('' === $tagName = $tag->nodeValue ?: $tag->getAttribute('name')) {
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in "%s" must be a non-empty string.', (string) $service->getAttribute('id'), $file));
}
Additional Context
The exception throw is the following:
Symfony\Component\DependencyInjection\Exception\InvalidArgumentException : The tag name for service "instacar.extra_filters.security_expression_value_provider" in "/home/bantonio/PhpstormProjects/FilterBundle/src/DependencyInjection/../Resources/config/security.xml" must be a non-empty string.