8000 Added support for deprecating aliases by j92 · Pull Request #24707 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Added support for deprecating aliases #24707

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter
< 8000 h3 class="SelectMenu-title">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
Prev Previous commit
Next Next commit
Added deprecation of aliases to the yaml file loader
  • Loading branch information
j92 committed Jan 26, 2018
commit 16a8676d8a2b87890bd5b2dae019038ccf4bb1fc
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,13 @@ private function parseDefinition($id, $service, $file, array $defaults)
}

foreach ($service as $key => $value) {
if (!in_array($key, array('alias', 'public'))) {
if (!in_array($key, array('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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the message be updated, too? Now it includes hardcoded keys for service aliases are "alias" and "public".

continue;
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
alias_for_foobar:
alias: foobar
deprecated: The "%service_id%" service alias is deprecated.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ public function testLoadServices()
$this->assertEquals(array('decorated', 'decorated.pif-pouf', 5), $services['decorator_service_with_name_and_priority']->getDecoratedService());
}

public function testDeprecatedAliases()
{
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('deprecated_alias_definitions.yml');

$this->assertTrue($container->getAlias('alias_for_foobar')->isDeprecated());
$message = 'The "alias_for_foobar" service alias is deprecated.';
$this->assertSame($message, $container->getAlias('alias_for_foobar')->getDeprecationMessage('alias_for_foobar'));
}

public function testLoadFactoryShortSyntax()
{
$container = new ContainerBuilder();
Expand Down
0