Skip to content

Commit e778ea6

Browse files
committed
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 ------- f603317 [DependencyInjection] Improve missing package/version deprecation
2 parents 773b4ef + f603317 commit e778ea6

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ private function parseDefinition(\DOMElement $service, string $file, Definition
205205
$version = $deprecated[0]->getAttribute('version') ?: '';
206206

207207
if (!$deprecated[0]->hasAttribute('package')) {
208-
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the node "deprecated" is deprecated.');
208+
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the node "deprecated" in "%s" is deprecated.', $file);
209209
}
210210

211211
if (!$deprecated[0]->hasAttribute('version')) {
212-
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the node "deprecated" is deprecated.');
212+
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the node "deprecated" in "%s" is deprecated.', $file);
213213
}
214214

215215
$alias->setDeprecated($package, $version, $message);
@@ -265,11 +265,11 @@ private function parseDefinition(\DOMElement $service, string $file, Definition
265265
$version = $deprecated[0]->getAttribute('version') ?: '';
266266

267267
if ('' === $package) {
268-
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the node "deprecated" is deprecated.');
268+
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the node "deprecated" in "%s" is deprecated.', $file);
269269
}
270270

271271
if ('' === $version) {
272-
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the node "deprecated" is deprecated.');
272+
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the node "deprecated" in "%s" is deprecated.', $file);
273273
}
274274

275275
$definition->setDeprecated($package, $version, $message);

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,11 @@ private function parseDefinition(string $id, $service, string $file, array $defa
409409
$deprecation = \is_array($value) ? $value : ['message' => $value];
410410

411411
if (!isset($deprecation['package'])) {
412-
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the "deprecated" option is deprecated.');
412+
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the "deprecated" option in "%s" is deprecated.', $file);
413413
}
414414

415415
if (!isset($deprecation['version'])) {
416-
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option is deprecated.');
416+
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.', $file);
417417
}
418418

419419
$alias->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message']);
@@ -478,11 +478,11 @@ private function parseDefinition(string $id, $service, string $file, array $defa
478478
$deprecation = \is_array($service['deprecated']) ? $service['deprecated'] : ['message' => $service['deprecated']];
479479

480480
if (!isset($deprecation['package'])) {
481-
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the "deprecated" option is deprecated.');
481+
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the "deprecated" option in "%s" is deprecated.', $file);
482482
}
483483

484484
if (!isset($deprecation['version'])) {
485-
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option is deprecated.');
485+
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.', $file);
486486
}
487487

488488
$definition->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message']);

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public function testDeprecated()
409409
*/
410410
public function testDeprecatedWithoutPackageAndVersion()
411411
{
412-
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated.');
412+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" in "%s" is deprecated.');
413413

414414
$container = new ContainerBuilder();
415415
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
@@ -442,7 +442,7 @@ public function testDeprecatedAliases()
442442
*/
443443
public function testDeprecatedAliaseWithoutPackageAndVersion()
444444
{
445-
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated.');
445+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" in "%s" is deprecated.');
446446

447447
$container = new ContainerBuilder();
448448
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ public function testDeprecatedAliases()
238238
*/
239239
public function testDeprecatedAliasesWithoutPackageAndVersion()
240240
{
241-
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the "deprecated" option is deprecated.');
242-
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "version" of the "deprecated" option is deprecated.');
241+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the "deprecated" option in "%s" is deprecated.');
242+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.');
243243

244244
$container = new ContainerBuilder();
245245
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));

0 commit comments

Comments
 (0)