Skip to content

Commit

Permalink
[DependencyInjection] Added information about deprecated aliases in d…
Browse files Browse the repository at this point in the history
…ebug: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 symfony#29968 and symfony#29995
  • Loading branch information
Anthony MARTIN committed Feb 5, 2019
1 parent 2cad97b commit e724fbd
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Expand Up @@ -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
-----
Expand Down
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Expand Up @@ -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
-----
Expand Down
Expand Up @@ -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);
}

Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -354,7 +354,7 @@ private function parseDefinition($id, $service, $file, array $defaults)
}

if ('deprecated' === $key) {
$alias->setDeprecated(true, $value);
$alias->setDeprecated(true, true === $value ? null : $value);
}
}

Expand Down
Expand Up @@ -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>
Expand Down

0 comments on commit e724fbd

Please sign in to comment.