Skip to content

Commit 4b17a3b

Browse files
author
Anthony MARTIN
committed
[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
1 parent 2cad97b commit 4b17a3b

File tree

8 files changed

+32
-5
lines changed

8 files changed

+32
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212
PHP's native `serialize()` and `unserialize()` functions. To use the
1313
original serialization method, set the `framework.messenger.serializer.id`
1414
config option to `messenger.transport.symfony_serializer`.
15+
* Added information about deprecated aliases in `debug:autowiring`
1516

1617
4.2.0
1718
-----

src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
104104
$serviceLine = sprintf('<fg=yellow>%s</>', $serviceId);
105105
if ($builder->hasAlias($serviceId)) {
106106
$hasAlias[$serviceId] = true;
107-
$serviceLine .= ' <fg=cyan>('.$builder->getAlias($serviceId).')</>';
107+
$serviceAlias = $builder->getAlias($serviceId);
108+
$serviceLine .= ' <fg=cyan>('.$serviceAlias.')</>';
109+
110+
if ($serviceAlias->isDeprecated()) {
111+
$serviceLine .= ' - <fg=magenta>deprecated</>';
112+
}
108113
} elseif (!$all) {
109114
continue;
110115
}

src/Symfony/Component/DependencyInjection/Alias.php

+5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ public function getDeprecationMessage(string $id): string
125125
return str_replace('%alias_id%', $id, $this->deprecationTemplate ?: self::$defaultDeprecationTemplate);
126126
}
127127

128+
public function getDeprecationTemplate(): ?string
129+
{
130+
return $this->deprecationTemplate;
131+
}
132+
128133
/**
129134
* Returns the Id of this alias.
130135
*

src/Symfony/Component/DependencyInjection/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* added `%env(trim:...)%` processor to trim a string value
88
* added `%env(default:...)%` processor to fallback to a default value
9+
* added support for deprecated aliases
910

1011
4.2.0
1112
-----

src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public function process(ContainerBuilder $container)
3434
$this->currentId = $id;
3535

3636
if ($aliasId !== $defId = $this->getDefinitionId($aliasId, $container)) {
37-
$container->setAlias($id, $defId)->setPublic($alias->isPublic())->setPrivate($alias->isPrivate());
37+
$container->setAlias($id, $defId)
38+
->setPublic($alias->isPublic())
39+
->setPrivate($alias->isPrivate())
40+
->setDeprecated($alias->isDeprecated(), $alias->getDeprecationTemplate());
3841
}
3942
}
4043
}

src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php

+10
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,16 @@ private function addServiceAlias($alias, Alias $id, \DOMElement $parent)
227227
if (!$id->isPrivate()) {
228228
$service->setAttribute('public', $id->isPublic() ? 'true' : 'false');
229229
}
230+
231+
if ($id->isDeprecated()) {
232+
$deprecated = $this->document->createElement('deprecated');
233+
if ($id->getDeprecationTemplate()) {
234+
$deprecated->nodeValue = $id->getDeprecationTemplate();
235+
}
236+
237+
$service->appendChild($deprecated);
238+
}
239+
230240
$parent->appendChild($service);
231241
}
232242

src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,13 @@ private function addService(string $id, Definition $definition): string
155155

156156
private function addServiceAlias(string $alias, Alias $id): string
157157
{
158+
$deprecated = $id->isDeprecated() ? sprintf(" deprecated: %s\n", $id->getDeprecationTemplate() ?: '') : '';
159+
158160
if ($id->isPrivate()) {
159-
return sprintf(" %s: '@%s'\n", $alias, $id);
161+
return sprintf(" %s: '@%s'\n%s", $alias, $id, $deprecated);
160162
}
161163

162-
return sprintf(" %s:\n alias: %s\n public: %s\n", $alias, $id, $id->isPublic() ? 'true' : 'false');
164+
return sprintf(" %s:\n alias: %s\n public: %s\n%s", $alias, $id, $id->isPublic() ? 'true' : 'false', $deprecated);
163165
}
164166

165167
private function addServices(): string

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ private function parseDefinition($id, $service, $file, array $defaults)
354354
}
355355

356356
if ('deprecated' === $key) {
357-
$alias->setDeprecated(true, $value);
357+
$alias->setDeprecated(true, \is_bool($value) ? null : $value);
358358
}
359359
}
360360

0 commit comments

Comments
 (0)