Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 13fdc92

Browse filesBrowse 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 symfony#29968 and symfony#29995
1 parent 2cad97b commit 13fdc92
Copy full SHA for 13fdc92

File tree

Expand file treeCollapse file tree

12 files changed

+37
-14
lines changed
Filter options
Expand file treeCollapse file tree

12 files changed

+37
-14
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php
+6-1Lines changed: 6 additions & 1 deletion
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/Bundle/FrameworkBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"symfony/cache": "~4.3",
2222
"symfony/config": "~4.2",
2323
"symfony/contracts": "^1.0.2",
24-
"symfony/dependency-injection": "^4.2",
24+
"symfony/dependency-injection": "^4.3",
2525
"symfony/event-dispatcher": "^4.1",
2626
"symfony/http-foundation": "^4.3",
2727
"symfony/http-kernel": "^4.2",

‎src/Symfony/Component/DependencyInjection/Alias.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Alias.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function isPrivate()
9898
*/
9999
public function setDeprecated($status = true, $template = null)
100100
{
101-
if (null !== $template) {
101+
if (null !== $template && true !== $template) {
102102
if (preg_match('#[\r\n]|\*/#', $template)) {
103103
throw new InvalidArgumentException('Invalid characters found in deprecation template.');
104104
}

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
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 deprecating aliases
910

1011
4.2.0
1112
-----

‎src/Symfony/Component/DependencyInjection/Definition.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Definition.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ public function isAbstract()
737737
*/
738738
public function setDeprecated($status = true, $template = null)
739739
{
740-
if (null !== $template) {
740+
if (null !== $template && true !== $template) {
741741
if (preg_match('#[\r\n]|\*/#', $template)) {
742742
throw new InvalidArgumentException('Invalid characters found in deprecation template.');
743743
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ 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+
$deprecated->appendChild($this->document->createTextNode($id->getDeprecationMessage('%alias_id%')));
234+
235+
$service->appendChild($deprecated);
236+
}
237+
230238
$parent->appendChild($service);
231239
}
232240

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
+4-2Lines changed: 4 additions & 2 deletions
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->getDeprecationMessage('%alias_id%')) : '';
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ private function parseDefinition($id, $service, $file, array $defaults)
350350

351351
foreach ($service as $key => $value) {
352352
if (!\in_array($key, ['alias', 'public', 'deprecated'])) {
353-
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));
353+
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));
354354
}
355355

356356
if ('deprecated' === $key) {

‎src/Symfony/Component/DependencyInjection/Tests/AliasTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/AliasTest.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public function testItHasADefaultDeprecationMessage()
6464

6565
$expectedMessage = 'The "foo" service alias is deprecated. You should stop using it, as it will be removed in the future.';
6666
$this->assertEquals($expectedMessage, $alias->getDeprecationMessage('foo'));
67+
68+
$alias->setDeprecated(true, true);
69+
$this->assertEquals($expectedMessage, $alias->getDeprecationMessage('foo'));
6770
}
6871

6972
public function testReturnsCorrectDeprecationMessage()
@@ -79,13 +82,10 @@ public function testCanOverrideDeprecation()
7982
{
8083
$alias = new Alias('foo', false);
8184
$alias->setDeprecated();
85+
$this->assertTrue($alias->isDeprecated());
8286

83-
$initial = $alias->isDeprecated();
8487
$alias->setDeprecated(false);
85-
$final = $alias->isDeprecated();
86-
87-
$this->assertTrue($initial);
88-
$this->assertFalse($final);
88+
$this->assertFalse($alias->isDeprecated());
8989
}
9090

9191
/**

‎src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,13 @@ public function testSetIsDeprecated()
164164
$this->assertFalse($def->isDeprecated(), '->isDeprecated() returns false by default');
165165
$this->assertSame($def, $def->setDeprecated(true), '->setDeprecated() implements a fluent interface');
166166
$this->assertTrue($def->isDeprecated(), '->isDeprecated() returns true if the instance should not be used anymore.');
167-
$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');
167+
168+
169+
$def->setDeprecated(true, true);
170+
$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 default formatted message template');
171+
172+
$def->setDeprecated(true, '%service_id%');
173+
$this->assertSame('deprecated_service', $def->getDeprecationMessage('deprecated_service'), '->getDeprecationMessage() should return given formatted message template');
168174
}
169175

170176
/**

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/deprecated_alias_definitions.xml

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/deprecated_alias_definitions.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<service id="foo" class="Foo">
55
</service>
66
<service id="alias_for_foo" alias="foo">
7-
<deprecated />
7+
<deprecated>The "%alias_id%" service alias is deprecated. You should stop using it, as it will be removed in the future.</deprecated>
88
</service>
99
<service id="alias_for_foobar" alias="foobar">
1010
<deprecated>The "%alias_id%" service alias is deprecated.</deprecated>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.