diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 9b9fdecee5bb0..ab62dc0b027ea 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -12,6 +12,7 @@ CHANGELOG PHP's native `serialize()` and `unserialize()` functions. To use the original serialization method, set the `framework.messenger.serializer.id` config option to `messenger.transport.symfony_serializer`. + * Added information about deprecated aliases in `debug:autowiring` 4.2.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php index a1097592ee784..97493eb28db24 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php @@ -104,7 +104,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $serviceLine = sprintf('%s', $serviceId); if ($builder->hasAlias($serviceId)) { $hasAlias[$serviceId] = true; - $serviceLine .= ' ('.$builder->getAlias($serviceId).')'; + $serviceAlias = $builder->getAlias($serviceId); + $serviceLine .= ' ('.$serviceAlias.')'; + + if ($serviceAlias->isDeprecated()) { + $serviceLine .= ' - deprecated'; + } } elseif (!$all) { continue; } diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index de270782d9a07..273788a925bf0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -21,7 +21,7 @@ "symfony/cache": "~4.3", "symfony/config": "~4.2", "symfony/contracts": "^1.0.2", - "symfony/dependency-injection": "^4.2", + "symfony/dependency-injection": "^4.3", "symfony/event-dispatcher": "^4.1", "symfony/http-foundation": "^4.3", "symfony/http-kernel": "^4.2", diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 7afa4a21b89a0..33d5a5f4220af 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -6,6 +6,7 @@ CHANGELOG * added `%env(trim:...)%` processor to trim a string value * added `%env(default:...)%` processor to fallback to a default value + * added support for deprecating aliases 4.2.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php index 625f126621907..704df2af3965e 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php @@ -227,6 +227,14 @@ private function addServiceAlias($alias, Alias $id, \DOMElement $parent) if (!$id->isPrivate()) { $service->setAttribute('public', $id->isPublic() ? 'true' : 'false'); } + + if ($id->isDeprecated()) { + $deprecated = $this->document->createElement('deprecated'); + $deprecated->appendChild($this->document->createTextNode($id->getDeprecationMessage('%alias_id%'))); + + $service->appendChild($deprecated); + } + $parent->appendChild($service); } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php index 2c07ebddad141..5b9e747315abd 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php @@ -155,11 +155,13 @@ private function addService(string $id, Definition $definition): string private function addServiceAlias(string $alias, Alias $id): string { + $deprecated = $id->isDeprecated() ? sprintf(" deprecated: %s\n", $id->getDeprecationMessage('%alias_id%')) : ''; + if ($id->isPrivate()) { - return sprintf(" %s: '@%s'\n", $alias, $id); + return sprintf(" %s: '@%s'\n%s", $alias, $id, $deprecated); } - return sprintf(" %s:\n alias: %s\n public: %s\n", $alias, $id, $id->isPublic() ? 'true' : 'false'); + return sprintf(" %s:\n alias: %s\n public: %s\n%s", $alias, $id, $id->isPublic() ? 'true' : 'false', $deprecated); } private function addServices(): string diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index d2be52f652dbe..e14d38d49d7f1 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -350,7 +350,7 @@ private function parseDefinition($id, $service, $file, array $defaults) foreach ($service as $key => $value) { if (!\in_array($key, ['alias', 'public', 'deprecated'])) { - throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for the service "%s" which is defined as an alias in "%s". Allowed configuration keys for service aliases are "alias" and "public".', $key, $id, $file)); + throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for the service "%s" which is defined as an alias in "%s". Allowed configuration keys for service aliases are "alias", "public" and "deprecated".', $key, $id, $file)); } if ('deprecated' === $key) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php b/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php index f9a9bb76fc846..f382450afc693 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php @@ -79,13 +79,10 @@ public function testCanOverrideDeprecation() { $alias = new Alias('foo', false); $alias->setDeprecated(); + $this->assertTrue($alias->isDeprecated()); - $initial = $alias->isDeprecated(); $alias->setDeprecated(false); - $final = $alias->isDeprecated(); - - $this->assertTrue($initial); - $this->assertFalse($final); + $this->assertFalse($alias->isDeprecated()); } /** @@ -105,6 +102,7 @@ public function invalidDeprecationMessageProvider() "With \ns" => ["invalid \n message %alias_id%"], 'With */s' => ['invalid */ message %alias_id%'], 'message not containing required %alias_id% variable' => ['this is deprecated'], + 'template not containing required %alias_id% variable' => [true], ]; } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php index aeef76122f030..3462726943037 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php @@ -164,7 +164,9 @@ public function testSetIsDeprecated() $this->assertFalse($def->isDeprecated(), '->isDeprecated() returns false by default'); $this->assertSame($def, $def->setDeprecated(true), '->setDeprecated() implements a fluent interface'); $this->assertTrue($def->isDeprecated(), '->isDeprecated() returns true if the instance should not be used anymore.'); - $this->assertSame('The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.', $def->getDeprecationMessage('deprecated_service'), '->getDeprecationMessage() should return a formatted message template'); + + $def->setDeprecated(true, '%service_id%'); + $this->assertSame('deprecated_service', $def->getDeprecationMessage('deprecated_service'), '->getDeprecationMessage() should return given formatted message template'); } /** @@ -184,6 +186,7 @@ public function invalidDeprecationMessageProvider() "With \ns" => ["invalid \n message %service_id%"], 'With */s' => ['invalid */ message %service_id%'], 'message not containing require %service_id% variable' => ['this is deprecated'], + 'template not containing require %service_id% variable' => [true], ]; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/deprecated_alias_definitions.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/deprecated_alias_definitions.xml index b122f92bf1f0a..69b9bbb15ea70 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/deprecated_alias_definitions.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/deprecated_alias_definitions.xml @@ -4,7 +4,7 @@ - + The "%alias_id%" service alias is deprecated. You should stop using it, as it will be removed in the future. The "%alias_id%" service alias is deprecated. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy