Skip to content

[DependencyInjection] Deprecate !tagged tag, use !tagged_iterator instead #57934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-7.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Cache

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

DependencyInjection
-------------------

* Deprecate `!tagged` tag, use `!tagged_iterator` instead

Form
----

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.2
---

* Deprecate `!tagged` tag, use `!tagged_iterator` instead

7.1
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ private function getArgumentsAsPhp(\DOMElement $node, string $name, string $file
$arguments[$key] = new ServiceLocatorArgument($arg);
break;
case 'tagged':
trigger_deprecation('symfony/dependency-injection', '7.2', 'Type "tagged" is deprecated for tag <%s>, use "tagged_iterator" instead in "%s".', $name, $file);
// no break
case 'tagged_iterator':
case 'tagged_locator':
$forLocator = 'tagged_locator' === $type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,10 @@ private function resolveServices(mixed $value, string $file, bool $isParameter =
return new ServiceLocatorArgument($argument);
}
if (\in_array($value->getTag(), ['tagged', 'tagged_iterator', 'tagged_locator'], true)) {
if ('tagged' === $value->getTag()) {
trigger_deprecation('symfony/dependency-injection', '7.2', 'Using "!tagged" is deprecated, use "!tagged_iterator" instead in "%s".', $file);
}

$forLocator = 'tagged_locator' === $value->getTag();

if (\is_array($argument) && isset($argument['tag']) && $argument['tag']) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<services>
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>
<service id="foo_tagged_iterator" class="Bar" public="true">
<argument type="tagged" tag="foo_tag" index-by="barfoo" default-index-method="foobar" default-priority-method="getPriority"/>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
iterator_service:
class: FooClass
arguments: [!tagged {tag: test.tag}]
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Tests\Loader;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
use Symfony\Component\Config\Exception\LoaderLoadException;
use Symfony\Component\Config\FileLocator;
Expand Down Expand Up @@ -48,6 +49,8 @@

class XmlFileLoaderTest extends TestCase
{
use ExpectDeprecationTrait;

protected static string $fixturesPath;

public static function setUpBeforeClass(): void
Expand Down Expand Up @@ -1276,4 +1279,17 @@ public function testStaticConstructorWithFactoryThrows()
$this->expectExceptionMessage('The "static_constructor" service cannot declare a factory as well as a constructor.');
$loader->load('static_constructor_and_factory.xml');
}

/**
* @group legacy
*/
public function testDeprecatedTagged()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));

$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'));

$loader->load('services_with_deprecated_tagged.xml');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Tests\Loader;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
use Symfony\Component\Config\Exception\LoaderLoadException;
use Symfony\Component\Config\FileLocator;
Expand Down Expand Up @@ -47,6 +48,8 @@

class YamlFileLoaderTest extends TestCase
{
use ExpectDeprecationTrait;

protected static string $fixturesPath;

public static function setUpBeforeClass(): void
Expand Down Expand Up @@ -1199,4 +1202,17 @@ public function testStaticConstructor()
$definition = $container->getDefinition('static_constructor');
$this->assertEquals((new Definition('stdClass'))->setFactory([null, 'create']), $definition);
}

/**
* @group legacy
*/
public function testDeprecatedTagged()
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));

$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'));

$loader->load('tagged_deprecated.yml');
}
}