Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 3 additions & 5 deletions src/Symfony/Component/DependencyInjection/Tests/AliasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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],
];
}

Expand Down
Original file line number Diff line number Diff line change
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