[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
This commit is contained in:
parent
2cad97b0b5
commit
3d2378dab5
@ -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 @@ EOF
|
||||
$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 @@ class XmlDumper extends Dumper
|
||||
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 @@ class YamlDumper extends Dumper
|
||||
|
||||
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 @@ class YamlFileLoader extends FileLoader
|
||||
|
||||
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 @@ class AliasTest extends TestCase
|
||||
{
|
||||
$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 @@ class AliasTest extends TestCase
|
||||
"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 @@ class DefinitionTest extends TestCase
|
||||
$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 @@ class DefinitionTest extends TestCase
|
||||
"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>
|
||||
|
Reference in New Issue
Block a user