Permalink
Browse files

feature #30075 [DependencyInjection] Added information about deprecat…

…ed aliases in debug:autowiring (XuruDragon)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[DependencyInjection] Added information about deprecated aliases in debug:autowiring

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT
| Doc PR        | n/a

Fix and improves a bit PR #29968 and #29995

![Screenshot](https://i.imgur.com/GDj2NIY.png)

Commits
-------

3d2378d [DependencyInjection] Added information about deprecated aliases in debug:autowiring
  • Loading branch information...
nicolas-grekas committed Feb 8, 2019
2 parents 7f3f75d + 3d2378d commit fd4306a3abf7783a8f8a2d194126bc6b84aa016a
@@ -12,6 +12,7 @@ CHANGELOG
PHP's native `serialize()` and `unserialize()` functions. To use the
original serialization method, set the `framework.messenger.serializer.id`
config option to `messenger.transport.symfony_serializer`.
* Added information about deprecated aliases in `debug:autowiring`

4.2.0
-----
@@ -104,7 +104,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$serviceLine = sprintf('<fg=yellow>%s</>', $serviceId);
if ($builder->hasAlias($serviceId)) {
$hasAlias[$serviceId] = true;
$serviceLine .= ' <fg=cyan>('.$builder->getAlias($serviceId).')</>';
$serviceAlias = $builder->getAlias($serviceId);
$serviceLine .= ' <fg=cyan>('.$serviceAlias.')</>';
if ($serviceAlias->isDeprecated()) {
$serviceLine .= ' - <fg=magenta>deprecated</>';
}
} elseif (!$all) {
continue;
}
@@ -21,7 +21,7 @@
"symfony/cache": "~4.3",
"symfony/config": "~4.2",
"symfony/contracts": "^1.0.2",
"symfony/dependency-injection": "^4.2",
"symfony/dependency-injection": "^4.3",
"symfony/event-dispatcher": "^4.1",
"symfony/http-foundation": "^4.3",
"symfony/http-kernel": "^4.2",
@@ -6,6 +6,7 @@ CHANGELOG

* added `%env(trim:...)%` processor to trim a string value
* added `%env(default:...)%` processor to fallback to a default value
* added support for deprecating aliases

4.2.0
-----
@@ -227,6 +227,14 @@ private function addServiceAlias($alias, Alias $id, \DOMElement $parent)
if (!$id->isPrivate()) {
$service->setAttribute('public', $id->isPublic() ? 'true' : 'false');
}
if ($id->isDeprecated()) {
$deprecated = $this->document->createElement('deprecated');
$deprecated->appendChild($this->document->createTextNode($id->getDeprecationMessage('%alias_id%')));
$service->appendChild($deprecated);
}
$parent->appendChild($service);
}
@@ -155,11 +155,13 @@ private function addService(string $id, Definition $definition): string
private function addServiceAlias(string $alias, Alias $id): string
{
$deprecated = $id->isDeprecated() ? sprintf(" deprecated: %s\n", $id->getDeprecationMessage('%alias_id%')) : '';
if ($id->isPrivate()) {
return sprintf(" %s: '@%s'\n", $alias, $id);
return sprintf(" %s: '@%s'\n%s", $alias, $id, $deprecated);
}
return sprintf(" %s:\n alias: %s\n public: %s\n", $alias, $id, $id->isPublic() ? 'true' : 'false');
return sprintf(" %s:\n alias: %s\n public: %s\n%s", $alias, $id, $id->isPublic() ? 'true' : 'false', $deprecated);
}
private function addServices(): string
@@ -350,7 +350,7 @@ private function parseDefinition($id, $service, $file, array $defaults)
foreach ($service as $key => $value) {
if (!\in_array($key, ['alias', 'public', 'deprecated'])) {
throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for the service "%s" which is defined as an alias in "%s". Allowed configuration keys for service aliases are "alias" and "public".', $key, $id, $file));
throw new InvalidArgumentException(sprintf('The configuration key "%s" is unsupported for the service "%s" which is defined as an alias in "%s". Allowed configuration keys for service aliases are "alias", "public" and "deprecated".', $key, $id, $file));
}
if ('deprecated' === $key) {
@@ -79,13 +79,10 @@ public function testCanOverrideDeprecation()
{
$alias = new Alias('foo', false);
$alias->setDeprecated();
$this->assertTrue($alias->isDeprecated());
$initial = $alias->isDeprecated();
$alias->setDeprecated(false);
$final = $alias->isDeprecated();
$this->assertTrue($initial);
$this->assertFalse($final);
$this->assertFalse($alias->isDeprecated());
}
/**
@@ -105,6 +102,7 @@ public function invalidDeprecationMessageProvider()
"With \ns" => ["invalid \n message %alias_id%"],
'With */s' => ['invalid */ message %alias_id%'],
'message not containing required %alias_id% variable' => ['this is deprecated'],
'template not containing required %alias_id% variable' => [true],
];
}
}
@@ -164,7 +164,9 @@ public function testSetIsDeprecated()
$this->assertFalse($def->isDeprecated(), '->isDeprecated() returns false by default');
$this->assertSame($def, $def->setDeprecated(true), '->setDeprecated() implements a fluent interface');
$this->assertTrue($def->isDeprecated(), '->isDeprecated() returns true if the instance should not be used anymore.');
$this->assertSame('The "deprecated_service" service is deprecated. You should stop using it, as it will be removed in the future.', $def->getDeprecationMessage('deprecated_service'), '->getDeprecationMessage() should return a formatted message template');
$def->setDeprecated(true, '%service_id%');
$this->assertSame('deprecated_service', $def->getDeprecationMessage('deprecated_service'), '->getDeprecationMessage() should return given formatted message template');
}
/**
@@ -184,6 +186,7 @@ public function invalidDeprecationMessageProvider()
"With \ns" => ["invalid \n message %service_id%"],
'With */s' => ['invalid */ message %service_id%'],
'message not containing require %service_id% variable' => ['this is deprecated'],
'template not containing require %service_id% variable' => [true],
];
}
@@ -4,7 +4,7 @@
<service id="foo" class="Foo">
</service>
<service id="alias_for_foo" alias="foo">
<deprecated />
<deprecated>The "%alias_id%" service alias is deprecated. You should stop using it, as it will be removed in the future.</deprecated>
</service>
<service id="alias_for_foobar" alias="foobar">
<deprecated>The "%alias_id%" service alias is deprecated.</deprecated>

0 comments on commit fd4306a

Please sign in to comment.