Skip to content

Commit 0bd53e4

Browse files
committed
feature #57934 [DependencyInjection] Deprecate !tagged tag, use !tagged_iterator instead (alexandre-daubois)
This PR was merged into the 7.2 branch. Discussion ---------- [DependencyInjection] Deprecate `!tagged` tag, use `!tagged_iterator` instead | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | yes | Issues | Fix #47805 | License | MIT Commits ------- 2318138 [DependencyInjection] Deprecate `!tagged` tag, use `!tagged_iterator` instead
2 parents cf3dfb6 + 2318138 commit 0bd53e4

File tree

8 files changed

+61
-0
lines changed

8 files changed

+61
-0
lines changed

UPGRADE-7.2.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Cache
1313

1414
* `igbinary_serialize()` is not used by default when the igbinary extension is installed
1515

16+
DependencyInjection
17+
-------------------
18+
19+
* Deprecate `!tagged` tag, use `!tagged_iterator` instead
20+
1621
Form
1722
----
1823

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.2
5+
---
6+
7+
* Deprecate `!tagged` tag, use `!tagged_iterator` instead
8+
49
7.1
510
---
611

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ private function getArgumentsAsPhp(\DOMElement $node, string $name, string $file
586586
$arguments[$key] = new ServiceLocatorArgument($arg);
587587
break;
588588
case 'tagged':
589+
trigger_deprecation('symfony/dependency-injection', '7.2', 'Type "tagged" is deprecated for tag <%s>, use "tagged_iterator" instead in "%s".', $name, $file);
590+
// no break
589591
case 'tagged_iterator':
590592
case 'tagged_locator':
591593
$forLocator = 'tagged_locator' === $type;

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,10 @@ private function resolveServices(mixed $value, string $file, bool $isParameter =
852852
return new ServiceLocatorArgument($argument);
853853
}
854854
if (\in_array($value->getTag(), ['tagged', 'tagged_iterator', 'tagged_locator'], true)) {
855+
if ('tagged' === $value->getTag()) {
856+
trigger_deprecation('symfony/dependency-injection', '7.2', 'Using "!tagged" is deprecated, use "!tagged_iterator" instead in "%s".', $file);
857+
}
858+
855859
$forLocator = 'tagged_locator' === $value->getTag();
856860

857861
if (\is_array($argument) && isset($argument['tag']) && $argument['tag']) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<services>
4+
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>
5+
<service id="foo_tagged_iterator" class="Bar" public="true">
6+
<argument type="tagged" tag="foo_tag" index-by="barfoo" default-index-method="foobar" default-priority-method="getPriority"/>
7+
</service>
8+
</services>
9+
</container>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
iterator_service:
3+
class: FooClass
4+
arguments: [!tagged {tag: test.tag}]

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Loader;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
1617
use Symfony\Component\Config\Exception\LoaderLoadException;
1718
use Symfony\Component\Config\FileLocator;
@@ -48,6 +49,8 @@
4849

4950
class XmlFileLoaderTest extends TestCase
5051
{
52+
use ExpectDeprecationTrait;
53+
5154
protected static string $fixturesPath;
5255

5356
public static function setUpBeforeClass(): void
@@ -1276,4 +1279,17 @@ public function testStaticConstructorWithFactoryThrows()
12761279
$this->expectExceptionMessage('The "static_constructor" service cannot declare a factory as well as a constructor.');
12771280
$loader->load('static_constructor_and_factory.xml');
12781281
}
1282+
1283+
/**
1284+
* @group legacy
1285+
*/
1286+
public function testDeprecatedTagged()
1287+
{
1288+
$container = new ContainerBuilder();
1289+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
1290+
1291+
$this->expectDeprecation(sprintf('Since symfony/dependency-injection 7.2: Type "tagged" is deprecated for tag <argument>, use "tagged_iterator" instead in "%s".', self::$fixturesPath.'/xml/services_with_deprecated_tagged.xml'));
1292+
1293+
$loader->load('services_with_deprecated_tagged.xml');
1294+
}
12791295
}

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Loader;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
1617
use Symfony\Component\Config\Exception\LoaderLoadException;
1718
use Symfony\Component\Config\FileLocator;
@@ -47,6 +48,8 @@
4748

4849
class YamlFileLoaderTest extends TestCase
4950
{
51+
use ExpectDeprecationTrait;
52+
5053
protected static string $fixturesPath;
5154

5255
public static function setUpBeforeClass(): void
@@ -1199,4 +1202,17 @@ public function testStaticConstructor()
11991202
$definition = $container->getDefinition('static_constructor');
12001203
$this->assertEquals((new Definition('stdClass'))->setFactory([null, 'create']), $definition);
12011204
}
1205+
1206+
/**
1207+
* @group legacy
1208+
*/
1209+
public function testDeprecatedTagged()
1210+
{
1211+
$container = new ContainerBuilder();
1212+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
1213+
1214+
$this->expectDeprecation(sprintf('Since symfony/dependency-injection 7.2: Using "!tagged" is deprecated, use "!tagged_iterator" instead in "%s".', self::$fixturesPath.'/yaml/tagged_deprecated.yml'));
1215+
1216+
$loader->load('tagged_deprecated.yml');
1217+
}
12021218
}

0 commit comments

Comments
 (0)