diff --git a/UPGRADE-5.1.md b/UPGRADE-5.1.md index 96c1c8b0e2d90..82f6d3a4af96e 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 4180954165f54..1f656683433ad 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 79e7e243471c8..0cc8f399f84d4 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 @@ public function __construct(string $id, bool $public = true) $this->id = $id; $this->public = $public; $this->private = 2 > \func_num_args(); - $this->deprecated = false; } /** @@ -85,40 +83,76 @@ public function isPrivate() * 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 0bacf3d561da7..f08356ae91837 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 f180d2290b4ae..c57b8e7f5608e 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php @@ -102,7 +102,8 @@ private function doResolveDefinition(ChildDefinition $definition): Definition $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 @@ private function doResolveDefinition(ChildDefinition $definition): Definition $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 086bc8780aeed..6d320e77f4766 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php @@ -62,7 +62,8 @@ private function getDefinitionId(string $id, ContainerBuilder $container): strin $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 a3c3e287460b6..f5b3cb96e6923 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -568,7 +568,8 @@ private function doGet(string $id, int $invalidBehavior = ContainerInterface::EX $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 @@ private function createService(Definition $definition, array &$inlineServices, b } 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 83b7cd2d7f852..163ce42e6d42a 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 @@ public function isAbstract() * 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 @@ public function setDeprecated(bool $status = true, string $template = null) */ 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 469effd9747a3..3ee7eba38a301 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -786,7 +786,8 @@ private function addService(string $id, Definition $definition): array $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 @@ protected function {$methodName}($lazyInitialization) $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 @@ private function addDeprecatedAliases(): string $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 @@ private function addDeprecatedAliases(): string */ 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 6f7d918d26af4..26521421bceaa 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php @@ -179,8 +179,11 @@ private function addService(Definition $definition, ?string $id, \DOMElement $pa } 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 @@ private function addServiceAlias(string $alias, Alias $id, \DOMElement $parent) } 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 9cfa23a7cf3f5..aeecd774d2a16 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php @@ -97,7 +97,12 @@ private function addService(string $id, Definition $definition): string } 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 @@ 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%')) : ''; + $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 b2d5b0eb78f5b..ea77e456d843d 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 74e828665d6fe..832a92656d811 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -205,7 +205,19 @@ private function parseDefinition(\DOMElement $service, string $file, array $defa } 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 @@ private function parseDefinition(\DOMElement $service, string $file, array $defa } 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 0a7971b86074b..a4e3caab1e7b4 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -358,7 +358,17 @@ private function parseDefinition(string $id, $service, string $file, array $defa } 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 @@ private function parseDefinition(string $id, $service, string $file, array $defa } 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 d2c81bcf311c7..673cf9cbe0e9e 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 7f35edc065084..79f82c64360fa 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/AliasTest.php @@ -52,33 +52,59 @@ public function testCanSetPublic() 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 @@ public function testCannotDeprecateWithAnInvalidTemplate($message) { $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 a220edd49339a..c7f8b43c9dceb 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -679,7 +679,7 @@ public function testInterfaceWithNoImplementationSuggestToWriteOne() 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 dfe37445d4e88..1cb78c557bbd1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php @@ -298,7 +298,7 @@ public function testDecoratedServiceCopiesDeprecatedStatusFromParent() { $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 @@ public function testDecoratedServiceCopiesDeprecatedStatusFromParent() $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 a2fece0580b86..c886ca4185f21 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveHotPathPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveHotPathPassTest.php @@ -41,8 +41,8 @@ public function testProcess() ->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 aad4fdf51432d..ba0ec103bbe45 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php @@ -174,11 +174,28 @@ public function testSetIsDeprecated() { $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 @@ public function testSetDeprecatedWithInvalidDeprecationTemplate($message) { $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 @@ public function testGetChangesWithChanges() $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 0000000000000..d0d3aa8455a40 --- /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 ebfe087d779cf..deb7abdc6e332 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 6a7d859df1fd6..2a308e19f554e 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 @@ ->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 ebfe087d779cf..deb7abdc6e332 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 501baa3c10ab7..9b070dc09bd25 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 @@ ->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 7c070ef64f450..0f669b374009a 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 @@ ->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 @@ ->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 6ae7f7161ab7f..d984f20e56dfe 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 ->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 ->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 5a9af100b772c..051cc6438e127 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 7ee91515a3933..3ba0060dc2f52 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 @@ protected function getDecoratorServiceWithNameService() * * @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 @@ protected function getTaggedIteratorService() * * @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 3ea888dd45f9e..7fec9d4dda154 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 d62d0dd5d415a..11ed6f9d47d2b 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 @@ protected function getDecoratorServiceWithNameService() * * @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 @@ protected function getTaggedIteratorService() * * @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 22264bf37e0b8..6f3e90a8fd32a 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 @@ public function isCompiled(): bool 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 538e7a53cd9e2..14873b484c2d1 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 @@ public function isCompiled(): bool 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 e12f71710bbd9..aba10028e14fd 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 @@ public function isCompiled(): bool 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 860f1c0d2b616..f45ee7e6a2d8f 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 0000000000000..0c4401712d196 --- /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 55ec20ee10059..e3b981c910611 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 ae3a0b089076c..9d4ef01bd3210 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 0000000000000..5051e3a766a85 --- /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 27738b7d8d2da..cbf121f9a41e8 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 0000000000000..27738b7d8d2da --- /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 fd2be046f8cd6..960b5b740a7fb 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 dd02ddb7e1eea..46570420a92f4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php @@ -100,4 +100,15 @@ public function testFactoryShortNotationNotAllowed() $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 55831540aa8d6..2fdac10213b16 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php @@ -394,11 +394,28 @@ public function testDeprecated() $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 @@ public function testDeprecatedAliases() $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 3d422c65069b6..8f38382df8404 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -213,7 +213,29 @@ public function testDeprecatedAliases() $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 @@ public function testParsesIteratorArgument() $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() 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