Skip to content

Commit f8cf281

Browse files
Merge branch '6.2' into 6.3
* 6.2: [Cache] Send Predis SSL options in the $hosts parameter [DependencyInjection] Do not ignore tags `name` attribute when it does not define their name [Contracts] Rename ServiceLocatorTest [Cache] Fix success interpretation when pruning cache Fix Psalm errors Make onAuthenticationSuccess Response optional [Security] Fix return type of AuthenticationSuccessHandlerInterface::onAuthenticationSuccess()
2 parents b7b5205 + d732a66 commit f8cf281

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

Loader/XmlFileLoader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,14 @@ private function parseDefinition(\DOMElement $service, string $file, Definition
345345
$tags = $this->getChildren($service, 'tag');
346346

347347
foreach ($tags as $tag) {
348-
if ('' === $tagName = $tag->childElementCount || '' === $tag->nodeValue ? $tag->getAttribute('name') : $tag->nodeValue) {
348+
$tagNameComesFromAttribute = $tag->childElementCount || '' === $tag->nodeValue;
349+
if ('' === $tagName = $tagNameComesFromAttribute ? $tag->getAttribute('name') : $tag->nodeValue) {
349350
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in "%s" must be a non-empty string.', (string) $service->getAttribute('id'), $file));
350351
}
351352

352353
$parameters = $this->getTagAttributes($tag, sprintf('The attribute name of tag "%s" for service "%s" in %s must be a non-empty string.', $tagName, (string) $service->getAttribute('id'), $file));
353354
foreach ($tag->attributes as $name => $node) {
354-
if ('name' === $name) {
355+
if ($tagNameComesFromAttribute && 'name' === $name) {
355356
continue;
356357
}
357358

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<services>
7+
<service id="foo" class="BarClass">
8+
<tag name="name_attribute">tag_name</tag>
9+
</service>
10+
</services>
11+
</container>

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,16 @@ public static function dataForBindingsAndInnerCollections()
12251225
];
12261226
}
12271227

1228+
public function testTagNameAttribute()
1229+
{
1230+
$container = new ContainerBuilder();
1231+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
1232+
$loader->load('tag_with_name_attribute.xml');
1233+
1234+
$definition = $container->getDefinition('foo');
1235+
$this->assertSame([['name' => 'name_attribute']], $definition->getTag('tag_name'));
1236+
}
1237+
12281238
public function testFromCallable()
12291239
{
12301240
$container = new ContainerBuilder();

Tests/ServiceLocatorTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1919
use Symfony\Component\DependencyInjection\ServiceLocator;
2020
use Symfony\Contracts\Service\ServiceSubscriberInterface;
21-
use Symfony\Contracts\Service\Test\ServiceLocatorTest as BaseServiceLocatorTest;
21+
use Symfony\Contracts\Service\Test\ServiceLocatorTest as LegacyServiceLocatorTestCase;
22+
use Symfony\Contracts\Service\Test\ServiceLocatorTestCase;
2223

23-
class ServiceLocatorTest extends BaseServiceLocatorTest
24+
if (!class_exists(ServiceLocatorTestCase::class)) {
25+
class_alias(LegacyServiceLocatorTestCase::class, ServiceLocatorTestCase::class);
26+
}
27+
28+
class ServiceLocatorTest extends ServiceLocatorTestCase
2429
{
2530
public function getServiceLocator(array $factories): ContainerInterface
2631
{

0 commit comments

Comments
 (0)