bug #37022 [DependencyInjection] Improve missing package/version deprecation (acrobat)
This PR was merged into the 5.1 branch.
Discussion
----------
[DependencyInjection] Improve missing package/version deprecation
| Q | A
| ------------- | ---
| Branch? | 5.1
| Bug fix? | yes
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets |
| License | MIT
| Doc PR |
After updating to symfony 5.1 I've got some deprecations related to the missing package/version attributes/options for `deprecated` on services.
But currently it's not clear which bundle/part of the code is triggering the deprecations. The only way for me to track down where they were coming from was by setting a xdebug breakpoint in the `XmlFileLoader` and check the `$file` variable.
So it seemed like a good idea to include the file path in the deprecation message, that way it will be easier for users to know if their code or a bundle (and which) is triggering this deprecation.
Before:
<img width="871" alt="Screenshot 2020-05-31 at 13 51 03" src="https://user-images.githubusercontent.com/1374857/83351609-d0d65600-a345-11ea-9785-3237a3ec2360.png">
After:
<img width="907" alt="Screenshot 2020-05-31 at 13 50 10" src="https://user-images.githubusercontent.com/1374857/83351606-cfa52900-a345-11ea-9617-60d07e46234b.png">
Commits
-------
f603317363
[DependencyInjection] Improve missing package/version deprecation
This commit is contained in:
commit
e778ea6367
@ -205,11 +205,11 @@ class XmlFileLoader extends FileLoader
|
||||
$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.');
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the node "deprecated" in "%s" is deprecated.', $file);
|
||||
}
|
||||
|
||||
if (!$deprecated[0]->hasAttribute('version')) {
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the node "deprecated" is deprecated.');
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the node "deprecated" in "%s" is deprecated.', $file);
|
||||
}
|
||||
|
||||
$alias->setDeprecated($package, $version, $message);
|
||||
@ -265,11 +265,11 @@ class XmlFileLoader extends FileLoader
|
||||
$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.');
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the node "deprecated" in "%s" is deprecated.', $file);
|
||||
}
|
||||
|
||||
if ('' === $version) {
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the node "deprecated" is deprecated.');
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the node "deprecated" in "%s" is deprecated.', $file);
|
||||
}
|
||||
|
||||
$definition->setDeprecated($package, $version, $message);
|
||||
|
@ -409,11 +409,11 @@ class YamlFileLoader extends FileLoader
|
||||
$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.');
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the "deprecated" option in "%s" is deprecated.', $file);
|
||||
}
|
||||
|
||||
if (!isset($deprecation['version'])) {
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option is deprecated.');
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.', $file);
|
||||
}
|
||||
|
||||
$alias->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message']);
|
||||
@ -478,11 +478,11 @@ class YamlFileLoader extends FileLoader
|
||||
$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.');
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the "deprecated" option in "%s" is deprecated.', $file);
|
||||
}
|
||||
|
||||
if (!isset($deprecation['version'])) {
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option is deprecated.');
|
||||
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.', $file);
|
||||
}
|
||||
|
||||
$definition->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message']);
|
||||
|
@ -409,7 +409,7 @@ class XmlFileLoaderTest extends TestCase
|
||||
*/
|
||||
public function testDeprecatedWithoutPackageAndVersion()
|
||||
{
|
||||
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated.');
|
||||
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" in "%s" is deprecated.');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
|
||||
@ -442,7 +442,7 @@ class XmlFileLoaderTest extends TestCase
|
||||
*/
|
||||
public function testDeprecatedAliaseWithoutPackageAndVersion()
|
||||
{
|
||||
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated.');
|
||||
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" in "%s" is deprecated.');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
|
||||
|
@ -238,8 +238,8 @@ class YamlFileLoaderTest extends TestCase
|
||||
*/
|
||||
public function testDeprecatedAliasesWithoutPackageAndVersion()
|
||||
{
|
||||
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the "deprecated" option is deprecated.');
|
||||
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "version" of the "deprecated" option is deprecated.');
|
||||
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the "deprecated" option in "%s" is deprecated.');
|
||||
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.');
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
|
Reference in New Issue
Block a user