From f10413cf34c1cd5eb915a0f8814ac016b1567833 Mon Sep 17 00:00:00 2001 From: Ahmed TAILOULOUTE Date: Tue, 18 Feb 2020 18:12:00 +0100 Subject: [PATCH] [DependencyInjection] improve the deprecation features by handling package+version info --- UPGRADE-5.1.md | 7 +++ UPGRADE-6.0.md | 7 +++ .../Component/DependencyInjection/Alias.php | 62 ++++++++++++++----- .../DependencyInjection/CHANGELOG.md | 3 + .../Compiler/ResolveChildDefinitionsPass.php | 10 ++- .../ResolveReferencesToAliasesPass.php | 3 +- .../DependencyInjection/ContainerBuilder.php | 6 +- .../DependencyInjection/Definition.php | 60 ++++++++++++++---- .../DependencyInjection/Dumper/PhpDumper.php | 13 ++-- .../DependencyInjection/Dumper/XmlDumper.php | 10 ++- .../DependencyInjection/Dumper/YamlDumper.php | 19 +++++- .../Configurator/Traits/DeprecateTrait.php | 21 ++++++- .../Loader/XmlFileLoader.php | 28 ++++++++- .../Loader/YamlFileLoader.php | 24 ++++++- .../schema/dic/services/services-1.0.xsd | 14 ++++- .../DependencyInjection/Tests/AliasTest.php | 42 ++++++++++--- .../Tests/Compiler/AutowirePassTest.php | 2 +- .../ResolveChildDefinitionsPassTest.php | 7 ++- .../Tests/Compiler/ResolveHotPathPassTest.php | 4 +- .../Tests/DefinitionTest.php | 25 ++++++-- .../deprecated_without_package_version.php | 10 +++ .../Fixtures/config/prototype.expected.yml | 10 ++- .../Tests/Fixtures/config/prototype.php | 2 +- .../config/prototype_array.expected.yml | 10 ++- .../Tests/Fixtures/config/prototype_array.php | 2 +- .../Tests/Fixtures/config/services9.php | 4 +- .../Tests/Fixtures/containers/container9.php | 4 +- .../Tests/Fixtures/php/services9_as_files.txt | 8 +-- .../Tests/Fixtures/php/services9_compiled.php | 8 +-- .../php/services9_inlined_factories.txt | 8 +-- .../php/services_errored_definition.php | 8 +-- .../Tests/Fixtures/php/services_rot13_env.php | 2 +- .../php/services_service_locator_argument.php | 2 +- .../Fixtures/php/services_subscriber.php | 4 +- .../xml/deprecated_alias_definitions.xml | 4 +- ...efinitions_without_package_and_version.xml | 10 +++ .../Tests/Fixtures/xml/services9.xml | 4 +- .../Fixtures/xml/services_deprecated.xml | 4 +- ...deprecated_without_package_and_version.xml | 8 +++ .../yaml/deprecated_alias_definitions.yml | 5 +- ...efinitions_without_package_and_version.yml | 4 ++ .../Tests/Fixtures/yaml/services9.yml | 10 ++- .../Tests/Loader/PhpFileLoaderTest.php | 11 ++++ .../Tests/Loader/XmlFileLoaderTest.php | 42 +++++++++++-- .../Tests/Loader/YamlFileLoaderTest.php | 26 +++++++- 45 files changed, 467 insertions(+), 110 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/deprecated_without_package_version.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/deprecated_alias_definitions_without_package_and_version.xml create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_deprecated_without_package_and_version.xml create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/deprecated_alias_definitions_without_package_and_version.yml diff --git a/UPGRADE-5.1.md b/UPGRADE-5.1.md index 96c1c8b0e2..82f6d3a4af 100644 --- a/UPGRADE-5.1.md +++ b/UPGRADE-5.1.md @@ -6,6 +6,13 @@ Console * `Command::setHidden()` is final since Symfony 5.1 +DependencyInjection +------------------- + + * The signature of method `Definition::setDeprecated()` has been updated to `Definition::setDeprecation(string $package, string $version, string $message)`. + * The signature of method `Alias::setDeprecated()` has been updated to `Alias::setDeprecation(string $package, string $version, string $message)`. + * The signature of method `DeprecateTrait::deprecate()` has been updated to `DeprecateTrait::deprecation(string $package, string $version, string $message)`. + Dotenv ------ diff --git a/UPGRADE-6.0.md b/UPGRADE-6.0.md index 4180954165..1f65668343 100644 --- a/UPGRADE-6.0.md +++ b/UPGRADE-6.0.md @@ -6,6 +6,13 @@ Console * `Command::setHidden()` has a default value (`true`) for `$hidden` parameter +DependencyInjection +------------------- + + * The signature of method `Definition::setDeprecated()` has been updated to `Definition::setDeprecation(string $package, string $version, string $message)`. + * The signature of method `Alias::setDeprecated()` has been updated to `Alias::setDeprecation(string $package, string $version, string $message)`. + * The signature of method `DeprecateTrait::deprecate()` has been updated to `DeprecateTrait::deprecation(string $package, string $version, string $message)`. + Dotenv ------ diff --git a/src/Symfony/Component/DependencyInjection/Alias.php b/src/Symfony/Component/DependencyInjection/Alias.php index 79e7e24347..0cc8f399f8 100644 --- a/src/Symfony/Component/DependencyInjection/Alias.php +++ b/src/Symfony/Component/DependencyInjection/Alias.php @@ -18,8 +18,7 @@ class Alias private $id; private $public; private $private; - private $deprecated; - private $deprecationTemplate; + private $deprecation = []; private static $defaultDeprecationTemplate = 'The "%alias_id%" service alias is deprecated. You should stop using it, as it will be removed in the future.'; @@ -28,7 +27,6 @@ class Alias $this->id = $id; $this->public = $public; $this->private = 2 > \func_num_args(); - $this->deprecated = false; } /** @@ -85,40 +83,76 @@ class Alias * Whether this alias is deprecated, that means it should not be referenced * anymore. * - * @param bool $status Whether this alias is deprecated, defaults to true - * @param string $template Optional template message to use if the alias is deprecated + * @param string $package The name of the composer package that is triggering the deprecation + * @param string $version The version of the package that introduced the deprecation + * @param string $message The deprecation message to use * * @return $this * * @throws InvalidArgumentException when the message template is invalid */ - public function setDeprecated(bool $status = true, string $template = null) + public function setDeprecated(/* string $package, string $version, string $message */) { - if (null !== $template) { - if (preg_match('#[\r\n]|\*/#', $template)) { + $args = \func_get_args(); + + if (\func_num_args() < 3) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'The signature of method "%s()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.', __METHOD__); + + $status = $args[0] ?? true; + + if (!$status) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'Passing a null message to un-deprecate a node is deprecated.'); + } + + $message = (string) ($args[1] ?? null); + $package = $version = ''; + } else { + $status = true; + $package = (string) $args[0]; + $version = (string) $args[1]; + $message = (string) $args[2]; + } + + if ('' !== $message) { + if (preg_match('#[\r\n]|\*/#', $message)) { throw new InvalidArgumentException('Invalid characters found in deprecation template.'); } - if (false === strpos($template, '%alias_id%')) { + if (false === strpos($message, '%alias_id%')) { throw new InvalidArgumentException('The deprecation template must contain the "%alias_id%" placeholder.'); } - - $this->deprecationTemplate = $template; } - $this->deprecated = $status; + $this->deprecation = $status ? ['package' => $package, 'version' => $version, 'message' => $message ?: self::$defaultDeprecationTemplate] : []; return $this; } public function isDeprecated(): bool { - return $this->deprecated; + return (bool) $this->deprecation; } + /** + * @deprecated since Symfony 5.1, use "getDeprecation()" instead. + */ public function getDeprecationMessage(string $id): string { - return str_replace('%alias_id%', $id, $this->deprecationTemplate ?: self::$defaultDeprecationTemplate); + trigger_deprecation('symfony/dependency-injection', '5.1', 'The "%s()" method is deprecated, use "getDeprecation()" instead.', __METHOD__); + + return $this->getDeprecation($id)['message']; + } + + /** + * @param string $id Service id relying on this definition + */ + public function getDeprecation(string $id): array + { + return [ + 'package' => $this->deprecation['package'], + 'version' => $this->deprecation['version'], + 'message' => str_replace('%alias_id%', $id, $this->deprecation['message']), + ]; } /** diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 0bacf3d561..f08356ae91 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -7,6 +7,9 @@ CHANGELOG * added support to autowire public typed properties in php 7.4 * added support for defining method calls, a configurator, and property setters in `InlineServiceConfigurator` * added possibility to define abstract service arguments + * updated the signature of method `Definition::setDeprecated()` to `Definition::setDeprecation(string $package, string $version, string $message)` + * updated the signature of method `Alias::setDeprecated()` to `Alias::setDeprecation(string $package, string $version, string $message)` + * updated the signature of method `DeprecateTrait::deprecate()` to `DeprecateTrait::deprecation(string $package, string $version, string $message)` 5.0.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php index f180d2290b..c57b8e7f56 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php @@ -102,7 +102,8 @@ class ResolveChildDefinitionsPass extends AbstractRecursivePass $def->setMethodCalls($parentDef->getMethodCalls()); $def->setProperties($parentDef->getProperties()); if ($parentDef->isDeprecated()) { - $def->setDeprecated(true, $parentDef->getDeprecationMessage('%service_id%')); + $deprecation = $parentDef->getDeprecation('%service_id%'); + $def->setDeprecated($deprecation['package'], $deprecation['version'], $deprecation['message']); } $def->setFactory($parentDef->getFactory()); $def->setConfigurator($parentDef->getConfigurator()); @@ -137,7 +138,12 @@ class ResolveChildDefinitionsPass extends AbstractRecursivePass $def->setLazy($definition->isLazy()); } if (isset($changes['deprecated'])) { - $def->setDeprecated($definition->isDeprecated(), $definition->getDeprecationMessage('%service_id%')); + if ($definition->isDeprecated()) { + $deprecation = $definition->getDeprecation('%service_id%'); + $def->setDeprecated($deprecation['package'], $deprecation['version'], $deprecation['message']); + } else { + $def->setDeprecated(false); + } } if (isset($changes['autowired'])) { $def->setAutowired($definition->isAutowired()); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php index 086bc8780a..6d320e77f4 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php @@ -62,7 +62,8 @@ class ResolveReferencesToAliasesPass extends AbstractRecursivePass $alias = $container->getAlias($id); if ($alias->isDeprecated()) { - trigger_deprecation('', '', '%s. It is being referenced by the "%s" %s.', rtrim($alias->getDeprecationMessage($id), '. '), $this->currentId, $container->hasDefinition($this->currentId) ? 'service' : 'alias'); + $deprecation = $alias->getDeprecation($id); + trigger_deprecation($deprecation['package'], $deprecation['version'], rtrim($deprecation['message'], '. ').'. It is being referenced by the "%s" '.($container->hasDefinition($this->currentId) ? 'service.' : 'alias.'), rtrim($deprecation['message'], '. '), $this->currentId); } $seen = []; diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index a3c3e28746..f5b3cb96e6 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -568,7 +568,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface $alias = $this->aliasDefinitions[$id]; if ($alias->isDeprecated()) { - trigger_deprecation('', '', $alias->getDeprecationMessage($id)); + $deprecation = $alias->getDeprecation($id); + trigger_deprecation($deprecation['package'], $deprecation['version'], $deprecation['message']); } return $this->doGet((string) $alias, $invalidBehavior, $inlineServices, $isConstructorArgument); @@ -1037,7 +1038,8 @@ class ContainerBuilder extends Container implements TaggedContainerInterface } if ($definition->isDeprecated()) { - trigger_deprecation('', '', $definition->getDeprecationMessage($id)); + $deprecation = $definition->getDeprecation($id); + trigger_deprecation($deprecation['package'], $deprecation['version'], $deprecation['message']); } if ($tryProxy && $definition->isLazy() && !$tryProxy = !($proxy = $this->proxyInstantiator) || $proxy instanceof RealServiceInstantiator) { diff --git a/src/Symfony/Component/DependencyInjection/Definition.php b/src/Symfony/Component/DependencyInjection/Definition.php index 83b7cd2d7f..163ce42e6d 100644 --- a/src/Symfony/Component/DependencyInjection/Definition.php +++ b/src/Symfony/Component/DependencyInjection/Definition.php @@ -26,8 +26,7 @@ class Definition private $file; private $factory; private $shared = true; - private $deprecated = false; - private $deprecationTemplate; + private $deprecation = []; private $properties = []; private $calls = []; private $instanceof = []; @@ -705,29 +704,48 @@ class Definition * Whether this definition is deprecated, that means it should not be called * anymore. * - * @param string $template Template message to use if the definition is deprecated + * @param string $package The name of the composer package that is triggering the deprecation + * @param string $version The version of the package that introduced the deprecation + * @param string $message The deprecation message to use * * @return $this * * @throws InvalidArgumentException when the message template is invalid */ - public function setDeprecated(bool $status = true, string $template = null) + public function setDeprecated(/* string $package, string $version, string $message */) { - if (null !== $template) { - if (preg_match('#[\r\n]|\*/#', $template)) { + $args = \func_get_args(); + + if (\func_num_args() < 3) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'The signature of method "%s()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.', __METHOD__); + + $status = $args[0] ?? true; + + if (!$status) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'Passing a null message to un-deprecate a node is deprecated.'); + } + + $message = (string) ($args[1] ?? null); + $package = $version = ''; + } else { + $status = true; + $package = (string) $args[0]; + $version = (string) $args[1]; + $message = (string) $args[2]; + } + + if ('' !== $message) { + if (preg_match('#[\r\n]|\*/#', $message)) { throw new InvalidArgumentException('Invalid characters found in deprecation template.'); } - if (false === strpos($template, '%service_id%')) { + if (false === strpos($message, '%service_id%')) { throw new InvalidArgumentException('The deprecation template must contain the "%service_id%" placeholder.'); } - - $this->deprecationTemplate = $template; } $this->changes['deprecated'] = true; - - $this->deprecated = $status; + $this->deprecation = $status ? ['package' => $package, 'version' => $version, 'message' => $message ?: self::$defaultDeprecationTemplate] : []; return $this; } @@ -740,19 +758,35 @@ class Definition */ public function isDeprecated() { - return $this->deprecated; + return (bool) $this->deprecation; } /** * Message to use if this definition is deprecated. * + * @deprecated since Symfony 5.1, use "getDeprecation()" instead. + * * @param string $id Service id relying on this definition * * @return string */ public function getDeprecationMessage(string $id) { - return str_replace('%service_id%', $id, $this->deprecationTemplate ?: self::$defaultDeprecationTemplate); + trigger_deprecation('symfony/dependency-injection', '5.1', 'The "%s()" method is deprecated, use "getDeprecation()" instead.', __METHOD__); + + return $this->getDeprecation($id)['message']; + } + + /** + * @param string $id Service id relying on this definition + */ + public function getDeprecation(string $id): array + { + return [ + 'package' => $this->deprecation['package'], + 'version' => $this->deprecation['version'], + 'message' => str_replace('%service_id%', $id, $this->deprecation['message']), + ]; } /** diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 469effd974..3ee7eba38a 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -786,7 +786,8 @@ EOF; $return[] = ''; } - $return[] = sprintf('@deprecated %s', $definition->getDeprecationMessage($id)); + $deprecation = $definition->getDeprecation($id); + $return[] = sprintf('@deprecated %s', ($deprecation['package'] || $deprecation['version'] ? "Since {$deprecation['package']} {$deprecation['version']}: " : '').$deprecation['message']); } $return = str_replace("\n * \n", "\n *\n", implode("\n * ", $return)); @@ -835,7 +836,8 @@ EOF; $this->inlinedDefinitions = $this->getDefinitionsFromArguments([$definition], null, $this->serviceCalls); if ($definition->isDeprecated()) { - $code .= sprintf(" trigger_deprecation('', '', %s);\n\n", $this->export($definition->getDeprecationMessage($id))); + $deprecation = $definition->getDeprecation($id); + $code .= sprintf(" trigger_deprecation(%s, %s, %s);\n\n", $this->export($deprecation['package']), $this->export($deprecation['version']), $this->export($deprecation['message'])); } else { foreach ($this->inlinedDefinitions as $def) { foreach ($this->getClasses($def) as $class) { @@ -1341,7 +1343,10 @@ EOF; $id = (string) $definition; $methodNameAlias = $this->generateMethodName($alias); $idExported = $this->export($id); - $messageExported = $this->export($definition->getDeprecationMessage($alias)); + $deprecation = $definition->getDeprecation($alias); + $packageExported = $this->export($deprecation['package']); + $versionExported = $this->export($deprecation['version']); + $messageExported = $this->export($deprecation['message']); $code .= <<docStar} @@ -1351,7 +1356,7 @@ EOF; */ protected function {$methodNameAlias}() { - trigger_deprecation('', '', $messageExported); + trigger_deprecation($packageExported, $versionExported, $messageExported); return \$this->get($idExported); } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php index 6f7d918d26..26521421bc 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php @@ -179,8 +179,11 @@ class XmlDumper extends Dumper } if ($definition->isDeprecated()) { + $deprecation = $definition->getDeprecation('%service_id%'); $deprecated = $this->document->createElement('deprecated'); - $deprecated->appendChild($this->document->createTextNode($definition->getDeprecationMessage('%service_id%'))); + $deprecated->appendChild($this->document->createTextNode($definition->getDeprecation('%service_id%')['message'])); + $deprecated->setAttribute('package', $deprecation['package']); + $deprecated->setAttribute('version', $deprecation['version']); $service->appendChild($deprecated); } @@ -225,8 +228,11 @@ class XmlDumper extends Dumper } if ($id->isDeprecated()) { + $deprecation = $id->getDeprecation('%alias_id%'); $deprecated = $this->document->createElement('deprecated'); - $deprecated->appendChild($this->document->createTextNode($id->getDeprecationMessage('%alias_id%'))); + $deprecated->setAttribute('message', $deprecation['message']); + $deprecated->setAttribute('package', $deprecation['package']); + $deprecated->setAttribute('version', $deprecation['version']); $service->appendChild($deprecated); } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php index 9cfa23a7cf..aeecd774d2 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php @@ -97,7 +97,12 @@ class YamlDumper extends Dumper } if ($definition->isDeprecated()) { - $code .= sprintf(" deprecated: %s\n", $this->dumper->dump($definition->getDeprecationMessage('%service_id%'))); + $code .= " deprecated:\n"; + foreach ($definition->getDeprecation('%service_id%') as $key => $value) { + if ('' !== $value) { + $code .= sprintf(" %s: %s\n", $key, $this->dumper->dump($value)); + } + } } if ($definition->isAutowired()) { @@ -162,7 +167,17 @@ class YamlDumper extends Dumper private function addServiceAlias(string $alias, Alias $id): string { - $deprecated = $id->isDeprecated() ? sprintf(" deprecated: %s\n", $id->getDeprecationMessage('%alias_id%')) : ''; + $deprecated = ''; + + if ($id->isDeprecated()) { + $deprecated = " deprecated:\n"; + + foreach ($id->getDeprecation('%alias_id%') as $key => $value) { + if ('' !== $value) { + $deprecated .= sprintf(" %s: %s\n", $key, $value); + } + } + } if ($id->isPrivate()) { return sprintf(" %s: '@%s'\n%s", $alias, $id, $deprecated); diff --git a/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/DeprecateTrait.php b/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/DeprecateTrait.php index b2d5b0eb78..ea77e456d8 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/DeprecateTrait.php +++ b/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/DeprecateTrait.php @@ -18,15 +18,30 @@ trait DeprecateTrait /** * Whether this definition is deprecated, that means it should not be called anymore. * - * @param string $template Template message to use if the definition is deprecated + * @param string $package The name of the composer package that is triggering the deprecation + * @param string $version The version of the package that introduced the deprecation + * @param string $message The deprecation message to use * * @return $this * * @throws InvalidArgumentException when the message template is invalid */ - final public function deprecate(string $template = null): self + final public function deprecate(/* string $package, string $version, string $message */): self { - $this->definition->setDeprecated(true, $template); + $args = \func_get_args(); + $package = $version = $message = ''; + + if (\func_num_args() < 3) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'The signature of method "%s()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.', __METHOD__); + + $message = (string) ($args[0] ?? null); + } else { + $package = (string) $args[0]; + $version = (string) $args[1]; + $message = (string) $args[2]; + } + + $this->definition->setDeprecated($package, $version, $message); return $this; } diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 74e828665d..832a92656d 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -205,7 +205,19 @@ class XmlFileLoader extends FileLoader } if ($deprecated = $this->getChildren($service, 'deprecated')) { - $alias->setDeprecated(true, $deprecated[0]->nodeValue ?: null); + $message = $deprecated[0]->nodeValue ?: ''; + $package = $deprecated[0]->getAttribute('package') ?: ''; + $version = $deprecated[0]->getAttribute('version') ?: ''; + + if (!$deprecated[0]->hasAttribute('package')) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the node "deprecated" is deprecated.'); + } + + if (!$deprecated[0]->hasAttribute('version')) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the node "deprecated" is deprecated.'); + } + + $alias->setDeprecated($package, $version, $message); } return null; @@ -284,7 +296,19 @@ class XmlFileLoader extends FileLoader } if ($deprecated = $this->getChildren($service, 'deprecated')) { - $definition->setDeprecated(true, $deprecated[0]->nodeValue ?: null); + $message = $deprecated[0]->nodeValue ?: ''; + $package = $deprecated[0]->getAttribute('package') ?: ''; + $version = $deprecated[0]->getAttribute('version') ?: ''; + + if ('' === $package) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the node "deprecated" is deprecated.'); + } + + if ('' === $version) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the node "deprecated" is deprecated.'); + } + + $definition->setDeprecated($package, $version, $message); } $definition->setArguments($this->getArgumentsAsPhp($service, 'argument', $file, $definition instanceof ChildDefinition)); diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 0a7971b860..a4e3caab1e 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -358,7 +358,17 @@ class YamlFileLoader extends FileLoader } if ('deprecated' === $key) { - $alias->setDeprecated(true, $value); + $deprecation = \is_array($value) ? $value : ['message' => $value]; + + if (!isset($deprecation['package'])) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the "deprecated" option is deprecated.'); + } + + if (!isset($deprecation['version'])) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option is deprecated.'); + } + + $alias->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message']); } } @@ -435,7 +445,17 @@ class YamlFileLoader extends FileLoader } if (\array_key_exists('deprecated', $service)) { - $definition->setDeprecated(true, $service['deprecated']); + $deprecation = \is_array($service['deprecated']) ? $service['deprecated'] : ['message' => $service['deprecated']]; + + if (!isset($deprecation['package'])) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the "deprecated" option is deprecated.'); + } + + if (!isset($deprecation['version'])) { + trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option is deprecated.'); + } + + $definition->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message']); } if (isset($service['factory'])) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd b/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd index d2c81bcf31..673cf9cbe0 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd +++ b/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd @@ -113,7 +113,7 @@ - + @@ -157,7 +157,7 @@ - + @@ -181,6 +181,16 @@ + + + + + + + + + + diff --git a/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php b/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php index 7f35edc065..79f82c6436 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php @@ -52,33 +52,59 @@ class AliasTest extends TestCase public function testCanDeprecateAnAlias() { $alias = new Alias('foo', false); - $alias->setDeprecated(true, 'The %alias_id% service is deprecated.'); + $alias->setDeprecated('vendor/package', '1.1', 'The %alias_id% service is deprecated.'); $this->assertTrue($alias->isDeprecated()); } + /** + * @group legacy + * @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated. + */ public function testItHasADefaultDeprecationMessage() { $alias = new Alias('foo', false); $alias->setDeprecated(); $expectedMessage = 'The "foo" service alias is deprecated. You should stop using it, as it will be removed in the future.'; - $this->assertEquals($expectedMessage, $alias->getDeprecationMessage('foo')); + $this->assertEquals($expectedMessage, $alias->getDeprecation('foo')['message']); } - public function testReturnsCorrectDeprecationMessage() + /** + * @group legacy + * @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated. + */ + public function testSetDeprecatedWithoutPackageAndVersion() + { + $def = new Alias('stdClass'); + $def->setDeprecated(true, '%alias_id%'); + + $deprecation = $def->getDeprecation('deprecated_alias'); + $this->assertSame('deprecated_alias', $deprecation['message']); + $this->assertSame('', $deprecation['package']); + $this->assertSame('', $deprecation['version']); + } + + public function testReturnsCorrectDeprecation() { $alias = new Alias('foo', false); - $alias->setDeprecated(true, 'The "%alias_id%" is deprecated.'); + $alias->setDeprecated('vendor/package', '1.1', 'The "%alias_id%" is deprecated.'); - $expectedMessage = 'The "foo" is deprecated.'; - $this->assertEquals($expectedMessage, $alias->getDeprecationMessage('foo')); + $deprecation = $alias->getDeprecation('foo'); + $this->assertEquals('The "foo" is deprecated.', $deprecation['message']); + $this->assertEquals('vendor/package', $deprecation['package']); + $this->assertEquals('1.1', $deprecation['version']); } + /** + * @group legacy + * @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated. + * @expectedDeprecation Since symfony/dependency-injection 5.1: Passing a null message to un-deprecate a node is deprecated. + */ public function testCanOverrideDeprecation() { $alias = new Alias('foo', false); - $alias->setDeprecated(); + $alias->setDeprecated('vendor/package', '1.1', 'The "%alias_id%" is deprecated.'); $this->assertTrue($alias->isDeprecated()); $alias->setDeprecated(false); @@ -92,7 +118,7 @@ class AliasTest extends TestCase { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $def = new Alias('foo'); - $def->setDeprecated(true, $message); + $def->setDeprecated('package', '1.1', $message); } public function invalidDeprecationMessageProvider() diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index a220edd493..c7f8b43c9d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -679,7 +679,7 @@ class AutowirePassTest extends TestCase public function testProcessDoesNotTriggerDeprecations() { $container = new ContainerBuilder(); - $container->register('deprecated', 'Symfony\Component\DependencyInjection\Tests\Fixtures\DeprecatedClass')->setDeprecated(true); + $container->register('deprecated', 'Symfony\Component\DependencyInjection\Tests\Fixtures\DeprecatedClass')->setDeprecated('vendor/package', '1.1', '%service_id%'); $container->register('foo', Foo::class); $container->register('bar', Bar::class)->setAutowired(true); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php index dfe37445d4..1cb78c557b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php @@ -298,7 +298,7 @@ class ResolveChildDefinitionsPassTest extends TestCase { $container = new ContainerBuilder(); $container->register('deprecated_parent') - ->setDeprecated(true) + ->setDeprecated('vendor/package', '1.1', '%service_id%') ; $container->setDefinition('decorated_deprecated_parent', new ChildDefinition('deprecated_parent')); @@ -308,6 +308,11 @@ class ResolveChildDefinitionsPassTest extends TestCase $this->assertTrue($container->getDefinition('decorated_deprecated_parent')->isDeprecated()); } + /** + * @group legacy + * @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Definition::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated. + * @expectedDeprecation Since symfony/dependency-injection 5.1: Passing a null message to un-deprecate a node is deprecated. + */ public function testDecoratedServiceCanOverwriteDeprecatedParentStatus() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveHotPathPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveHotPathPassTest.php index a2fece0580..c886ca4185 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveHotPathPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveHotPathPassTest.php @@ -41,8 +41,8 @@ class ResolveHotPathPassTest extends TestCase ->addArgument(new Reference('lazy')) ->addArgument(new Reference('lazy')); $container->register('buz'); - $container->register('deprec_with_tag')->setDeprecated()->addTag('container.hot_path'); - $container->register('deprec_ref_notag')->setDeprecated(); + $container->register('deprec_with_tag')->setDeprecated('vendor/package', '1.1', '%service_id%')->addTag('container.hot_path'); + $container->register('deprec_ref_notag')->setDeprecated('vendor/package', '1.1', '%service_id%'); (new ResolveHotPathPass())->process($container); diff --git a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php index aad4fdf514..ba0ec103bb 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php @@ -174,11 +174,28 @@ class DefinitionTest extends TestCase { $def = new Definition('stdClass'); $this->assertFalse($def->isDeprecated(), '->isDeprecated() returns false by default'); - $this->assertSame($def, $def->setDeprecated(true), '->setDeprecated() implements a fluent interface'); + $this->assertSame($def, $def->setDeprecated('vendor/package', '1.1', '%service_id%'), '->setDeprecated() implements a fluent interface'); $this->assertTrue($def->isDeprecated(), '->isDeprecated() returns true if the instance should not be used anymore.'); + $deprecation = $def->getDeprecation('deprecated_service'); + $this->assertSame('deprecated_service', $deprecation['message'], '->getDeprecation() should return an array with the formatted message template'); + $this->assertSame('vendor/package', $deprecation['package']); + $this->assertSame('1.1', $deprecation['version']); + } + + /** + * @group legacy + * @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Definition::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated. + */ + public function testSetDeprecatedWithoutPackageAndVersion() + { + $def = new Definition('stdClass'); $def->setDeprecated(true, '%service_id%'); - $this->assertSame('deprecated_service', $def->getDeprecationMessage('deprecated_service'), '->getDeprecationMessage() should return given formatted message template'); + + $deprecation = $def->getDeprecation('deprecated_service'); + $this->assertSame('deprecated_service', $deprecation['message']); + $this->assertSame('', $deprecation['package']); + $this->assertSame('', $deprecation['version']); } /** @@ -188,7 +205,7 @@ class DefinitionTest extends TestCase { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); $def = new Definition('stdClass'); - $def->setDeprecated(false, $message); + $def->setDeprecated('vendor/package', '1.1', $message); } public function invalidDeprecationMessageProvider() @@ -341,7 +358,7 @@ class DefinitionTest extends TestCase $def->setAutowired(true); $def->setConfigurator('configuration_func'); $def->setDecoratedService(null); - $def->setDeprecated(true); + $def->setDeprecated('vendor/package', '1.1', '%service_id%'); $def->setFactory('factory_func'); $def->setFile('foo.php'); $def->setLazy(true); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/deprecated_without_package_version.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/deprecated_without_package_version.php new file mode 100644 index 0000000000..d0d3aa8455 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/deprecated_without_package_version.php @@ -0,0 +1,10 @@ +services() + ->set('foo', 'stdClass') + ->deprecate('%service_id%') + ; +}; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype.expected.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype.expected.yml index ebfe087d77..deb7abdc6e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype.expected.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype.expected.yml @@ -10,7 +10,10 @@ services: tags: - { name: foo } - { name: baz } - deprecated: '%service_id%' + deprecated: + package: vendor/package + version: '1.1' + message: '%service_id%' arguments: [1] factory: f Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar: @@ -19,7 +22,10 @@ services: tags: - { name: foo } - { name: baz } - deprecated: '%service_id%' + deprecated: + package: vendor/package + version: '1.1' + message: '%service_id%' lazy: true arguments: [1] factory: f diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype.php index 6a7d859df1..2a308e19f5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype.php @@ -11,7 +11,7 @@ return function (ContainerConfigurator $c) { ->autoconfigure() ->exclude('../Prototype/{OtherDir,BadClasses,SinglyImplementedInterface}') ->factory('f') - ->deprecate('%service_id%') + ->deprecate('vendor/package', '1.1', '%service_id%') ->args([0]) ->args([1]) ->autoconfigure(false) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype_array.expected.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype_array.expected.yml index ebfe087d77..deb7abdc6e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype_array.expected.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype_array.expected.yml @@ -10,7 +10,10 @@ services: tags: - { name: foo } - { name: baz } - deprecated: '%service_id%' + deprecated: + package: vendor/package + version: '1.1' + message: '%service_id%' arguments: [1] factory: f Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\Bar: @@ -19,7 +22,10 @@ services: tags: - { name: foo } - { name: baz } - deprecated: '%service_id%' + deprecated: + package: vendor/package + version: '1.1' + message: '%service_id%' lazy: true arguments: [1] factory: f diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype_array.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype_array.php index 501baa3c10..9b070dc09b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype_array.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/prototype_array.php @@ -11,7 +11,7 @@ return function (ContainerConfigurator $c) { ->autoconfigure() ->exclude(['../Prototype/OtherDir', '../Prototype/BadClasses', '../Prototype/SinglyImplementedInterface']) ->factory('f') - ->deprecate('%service_id%') + ->deprecate('vendor/package', '1.1', '%service_id%') ->args([0]) ->args([1]) ->autoconfigure(false) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/services9.php index 7c070ef64f..0f669b3740 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/services9.php @@ -88,7 +88,7 @@ return function (ContainerConfigurator $c) { ->decorate('decorated', 'decorated.pif-pouf'); $s->set('deprecated_service', 'stdClass') - ->deprecate(); + ->deprecate('vendor/package', '1.1', 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.'); $s->set('new_factory', 'FactoryClass') ->property('foo', 'bar') @@ -105,7 +105,7 @@ return function (ContainerConfigurator $c) { ->factory(['Bar\FooClass', 'getInstance']); $s->set('factory_simple', 'SimpleFactoryClass') - ->deprecate() + ->deprecate('vendor/package', '1.1', 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.') ->args(['foo']) ->private(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php index 6ae7f7161a..d984f20e56 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php @@ -115,7 +115,7 @@ $container ; $container ->register('deprecated_service', 'stdClass') - ->setDeprecated(true) + ->setDeprecated('vendor/package', '1.1', 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.') ->setPublic(true) ; $container @@ -142,7 +142,7 @@ $container $container ->register('factory_simple', 'SimpleFactoryClass') ->addArgument('foo') - ->setDeprecated(true) + ->setDeprecated('vendor/package', '1.1', 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.') ->setPublic(false) ; $container diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt index 5a9af100b7..051cc6438e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt @@ -239,11 +239,11 @@ class getDeprecatedServiceService extends ProjectServiceContainer * * @return \stdClass * - * @deprecated The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future. + * @deprecated Since vendor/package 1.1: The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future. */ public static function do($container, $lazyLoad = true) { - trigger_deprecation('', '', 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.'); + trigger_deprecation('vendor/package', '1.1', 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.'); return $container->services['deprecated_service'] = new \stdClass(); } @@ -312,11 +312,11 @@ class getFactorySimpleService extends ProjectServiceContainer * * @return \SimpleFactoryClass * - * @deprecated The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future. + * @deprecated Since vendor/package 1.1: The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future. */ public static function do($container, $lazyLoad = true) { - trigger_deprecation('', '', 'The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.'); + trigger_deprecation('vendor/package', '1.1', 'The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.'); return new \SimpleFactoryClass('foo'); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index 7ee91515a3..3ba0060dc2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -203,11 +203,11 @@ class ProjectServiceContainer extends Container * * @return \stdClass * - * @deprecated The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future. + * @deprecated Since vendor/package 1.1: The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future. */ protected function getDeprecatedServiceService() { - trigger_deprecation('', '', 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.'); + trigger_deprecation('vendor/package', '1.1', 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.'); return $this->services['deprecated_service'] = new \stdClass(); } @@ -397,11 +397,11 @@ class ProjectServiceContainer extends Container * * @return \SimpleFactoryClass * - * @deprecated The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future. + * @deprecated Since vendor/package 1.1: The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future. */ protected function getFactorySimpleService() { - trigger_deprecation('', '', 'The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.'); + trigger_deprecation('vendor/package', '1.1', 'The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.'); return new \SimpleFactoryClass('foo'); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt index 3ea888dd45..7fec9d4dda 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt @@ -226,11 +226,11 @@ class ProjectServiceContainer extends Container * * @return \stdClass * - * @deprecated The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future. + * @deprecated Since vendor/package 1.1: The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future. */ protected function getDeprecatedServiceService() { - trigger_deprecation('', '', 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.'); + trigger_deprecation('vendor/package', '1.1', 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.'); return $this->services['deprecated_service'] = new \stdClass(); } @@ -448,11 +448,11 @@ class ProjectServiceContainer extends Container * * @return \SimpleFactoryClass * - * @deprecated The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future. + * @deprecated Since vendor/package 1.1: The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future. */ protected function getFactorySimpleService() { - trigger_deprecation('', '', 'The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.'); + trigger_deprecation('vendor/package', '1.1', 'The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.'); return new \SimpleFactoryClass('foo'); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php index d62d0dd5d4..11ed6f9d47 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php @@ -203,11 +203,11 @@ class Symfony_DI_PhpDumper_Errored_Definition extends Container * * @return \stdClass * - * @deprecated The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future. + * @deprecated Since vendor/package 1.1: The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future. */ protected function getDeprecatedServiceService() { - trigger_deprecation('', '', 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.'); + trigger_deprecation('vendor/package', '1.1', 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.'); return $this->services['deprecated_service'] = new \stdClass(); } @@ -397,11 +397,11 @@ class Symfony_DI_PhpDumper_Errored_Definition extends Container * * @return \SimpleFactoryClass * - * @deprecated The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future. + * @deprecated Since vendor/package 1.1: The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future. */ protected function getFactorySimpleService() { - trigger_deprecation('', '', 'The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.'); + trigger_deprecation('vendor/package', '1.1', 'The "factory_simple" service is deprecated. You should stop using it, as it will be removed in the future.'); return new \SimpleFactoryClass('foo'); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_rot13_env.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_rot13_env.php index 22264bf37e..6f3e90a8fd 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_rot13_env.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_rot13_env.php @@ -44,7 +44,7 @@ class Symfony_DI_PhpDumper_Test_Rot13Parameters extends Container public function getRemovedIds(): array { return [ - '.service_locator.ZZqL6HL' => true, + '.service_locator.PnIy5ic' => true, 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, ]; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_service_locator_argument.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_service_locator_argument.php index 538e7a53cd..14873b484c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_service_locator_argument.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_service_locator_argument.php @@ -45,7 +45,7 @@ class Symfony_DI_PhpDumper_Service_Locator_Argument extends Container public function getRemovedIds(): array { return [ - '.service_locator.iSxuxv5' => true, + '.service_locator.VAwNRfI' => true, 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'foo2' => true, diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php index e12f71710b..aba10028e1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_subscriber.php @@ -42,8 +42,8 @@ class ProjectServiceContainer extends Container public function getRemovedIds(): array { return [ - '.service_locator.2Wk0Efb' => true, - '.service_locator.2Wk0Efb.foo_service' => true, + '.service_locator.Csd_kfL' => true, + '.service_locator.Csd_kfL.foo_service' => true, 'Psr\\Container\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => 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 860f1c0d2b..f45ee7e6a2 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,10 +4,10 @@ - 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. You should stop using it, as it will be removed in the future. - The "%alias_id%" service alias is deprecated. + The "%alias_id%" service alias is deprecated. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/deprecated_alias_definitions_without_package_and_version.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/deprecated_alias_definitions_without_package_and_version.xml new file mode 100644 index 0000000000..0c4401712d --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/deprecated_alias_definitions_without_package_and_version.xml @@ -0,0 +1,10 @@ + + + + + + + The "%alias_id%" service alias is deprecated. You should stop using it, as it will be removed in the future. + + + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml index 55ec20ee10..e3b981c910 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml @@ -97,7 +97,7 @@ - The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future. + The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future. bar @@ -114,7 +114,7 @@ foo - The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future. + The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_deprecated.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_deprecated.xml index ae3a0b0890..9d4ef01bd3 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_deprecated.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_deprecated.xml @@ -2,10 +2,10 @@ - + - The "%service_id%" service is deprecated. + The "%service_id%" service is deprecated. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_deprecated_without_package_and_version.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_deprecated_without_package_and_version.xml new file mode 100644 index 0000000000..5051e3a766 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_deprecated_without_package_and_version.xml @@ -0,0 +1,8 @@ + + + + + The "%service_id%" service is deprecated. + + + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/deprecated_alias_definitions.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/deprecated_alias_definitions.yml index 27738b7d8d..cbf121f9a4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/deprecated_alias_definitions.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/deprecated_alias_definitions.yml @@ -1,4 +1,7 @@ services: alias_for_foobar: alias: foobar - deprecated: The "%alias_id%" service alias is deprecated. + deprecated: + package: vendor/package + version: 1.1 + message: The "%alias_id%" service alias is deprecated. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/deprecated_alias_definitions_without_package_and_version.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/deprecated_alias_definitions_without_package_and_version.yml new file mode 100644 index 0000000000..27738b7d8d --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/deprecated_alias_definitions_without_package_and_version.yml @@ -0,0 +1,4 @@ +services: + alias_for_foobar: + alias: foobar + deprecated: The "%alias_id%" service alias is deprecated. diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml index fd2be046f8..960b5b740a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml @@ -103,7 +103,10 @@ services: public: true deprecated_service: class: stdClass - deprecated: The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future. + deprecated: + message: The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future. + package: vendor/package + version: 1.1 public: true new_factory: class: FactoryClass @@ -124,7 +127,10 @@ services: public: true factory_simple: class: SimpleFactoryClass - deprecated: The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future. + deprecated: + message: The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future. + package: vendor/package + version: 1.1 public: false arguments: ['foo'] factory_service_simple: diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php index dd02ddb7e1..46570420a9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php @@ -100,4 +100,15 @@ class PhpFileLoaderTest extends TestCase $loader->load($fixtures.'/config/factory_short_notation.php'); $container->compile(); } + + /** + * @group legacy + * @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Loader\Configurator\Traits\DeprecateTrait::deprecate()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated. + */ + public function testDeprecatedWithoutPackageAndVersion() + { + $fixtures = realpath(__DIR__.'/../Fixtures'); + $loader = new PhpFileLoader($container = new ContainerBuilder(), new FileLocator()); + $loader->load($fixtures.'/config/deprecated_without_package_version.php'); + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php index 55831540aa..2fdac10213 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php @@ -394,11 +394,28 @@ class XmlFileLoaderTest extends TestCase $this->assertTrue($container->getDefinition('foo')->isDeprecated()); $message = 'The "foo" service is deprecated. You should stop using it, as it will be removed in the future.'; - $this->assertSame($message, $container->getDefinition('foo')->getDeprecationMessage('foo')); + $this->assertSame($message, $container->getDefinition('foo')->getDeprecation('foo')['message']); $this->assertTrue($container->getDefinition('bar')->isDeprecated()); $message = 'The "bar" service is deprecated.'; - $this->assertSame($message, $container->getDefinition('bar')->getDeprecationMessage('bar')); + $this->assertSame($message, $container->getDefinition('bar')->getDeprecation('bar')['message']); + } + + /** + * @group legacy + * @expectedDeprecation Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated. + */ + public function testDeprecatedWithoutPackageAndVersion() + { + $container = new ContainerBuilder(); + $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); + $loader->load('services_deprecated_without_package_and_version.xml'); + + $this->assertTrue($container->getDefinition('foo')->isDeprecated()); + $deprecation = $container->getDefinition('foo')->getDeprecation('foo'); + $this->assertSame('The "foo" service is deprecated.', $deprecation['message']); + $this->assertSame('', $deprecation['package']); + $this->assertSame('', $deprecation['version']); } public function testDeprecatedAliases() @@ -409,11 +426,28 @@ class XmlFileLoaderTest extends TestCase $this->assertTrue($container->getAlias('alias_for_foo')->isDeprecated()); $message = 'The "alias_for_foo" service alias is deprecated. You should stop using it, as it will be removed in the future.'; - $this->assertSame($message, $container->getAlias('alias_for_foo')->getDeprecationMessage('alias_for_foo')); + $this->assertSame($message, $container->getAlias('alias_for_foo')->getDeprecation('alias_for_foo')['message']); $this->assertTrue($container->getAlias('alias_for_foobar')->isDeprecated()); $message = 'The "alias_for_foobar" service alias is deprecated.'; - $this->assertSame($message, $container->getAlias('alias_for_foobar')->getDeprecationMessage('alias_for_foobar')); + $this->assertSame($message, $container->getAlias('alias_for_foobar')->getDeprecation('alias_for_foobar')['message']); + } + + /** + * @group legacy + * @expectedDeprecation Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated. + */ + public function testDeprecatedAliaseWithoutPackageAndVersion() + { + $container = new ContainerBuilder(); + $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); + $loader->load('deprecated_alias_definitions_without_package_and_version.xml'); + + $this->assertTrue($container->getAlias('alias_for_foo')->isDeprecated()); + $deprecation = $container->getAlias('alias_for_foo')->getDeprecation('alias_for_foo'); + $this->assertSame('The "alias_for_foo" service alias is deprecated. You should stop using it, as it will be removed in the future.', $deprecation['message']); + $this->assertSame('', $deprecation['package']); + $this->assertSame('', $deprecation['version']); } public function testConvertDomElementToArray() diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 3d422c6506..8f38382df8 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -213,7 +213,29 @@ class YamlFileLoaderTest extends TestCase $this->assertTrue($container->getAlias('alias_for_foobar')->isDeprecated()); $message = 'The "alias_for_foobar" service alias is deprecated.'; - $this->assertSame($message, $container->getAlias('alias_for_foobar')->getDeprecationMessage('alias_for_foobar')); + $deprecation = $container->getAlias('alias_for_foobar')->getDeprecation('alias_for_foobar'); + $this->assertSame($message, $deprecation['message']); + $this->assertSame('vendor/package', $deprecation['package']); + $this->assertSame('1.1', $deprecation['version']); + } + + /** + * @group legacy + * @expectedDeprecation Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the "deprecated" option is deprecated. + * @expectedDeprecation Since symfony/dependency-injection 5.1: Not setting the attribute "version" of the "deprecated" option is deprecated. + */ + public function testDeprecatedAliasesWithoutPackageAndVersion() + { + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); + $loader->load('deprecated_alias_definitions_without_package_and_version.yml'); + + $this->assertTrue($container->getAlias('alias_for_foobar')->isDeprecated()); + $message = 'The "alias_for_foobar" service alias is deprecated.'; + $deprecation = $container->getAlias('alias_for_foobar')->getDeprecation('alias_for_foobar'); + $this->assertSame($message, $deprecation['message']); + $this->assertSame('', $deprecation['package']); + $this->assertSame('', $deprecation['version']); } public function testFactorySyntaxError() @@ -376,7 +398,7 @@ class YamlFileLoaderTest extends TestCase $this->assertEquals([new IteratorArgument(['k1' => new Reference('foo.baz'), 'k2' => new Reference('service_container')]), new IteratorArgument([])], $lazyDefinition->getArguments(), '->load() parses lazy arguments'); $message = 'The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.'; - $this->assertSame($message, $container->getDefinition('deprecated_service')->getDeprecationMessage('deprecated_service')); + $this->assertSame($message, $container->getDefinition('deprecated_service')->getDeprecation('deprecated_service')['message']); } public function testAutowire()