8000 Added deprecation of aliases to the yaml file loader · symfony/symfony@ec52a09 · GitHub
[go: up one dir, main page]

Skip to content

Commit ec52a09

Browse files
committed
Added deprecation of aliases to the yaml file loader
1 parent aa459f9 commit ec52a09

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,13 @@ private function parseDefinition($id, $service, $file, array $defaults)
368368
}
369369

370370
foreach ($service as $key => $value) {
371-
if (!in_array($key, array('alias', 'public'))) {
371+
if (!in_array($key, array('alias', 'public', 'deprecated'))) {
372372
@trigger_error(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". The YamlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported attributes.', $key, $id, $file), E_USER_DEPRECATED);
373+
continue;
374+
}
375+
376+
if ('deprecated' === $key) {
377+
$alias->setDeprecated(true, $value);
373378
}
374379
}
375380

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
alias_for_foobar:
3+
alias: foobar
4+
deprecated: The "%service_id%" service alias is deprecated.

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ public function testLoadServices()
174174
$this->assertEquals(array('decorated', 'decorated.pif-pouf', 5), $services['decorator_service_with_name_and_priority']->getDecoratedService());
175175
}
176176

177+
public function testDeprecatedAliases()
178+
{
179+
$container = new ContainerBuilder();
180+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
181+
$loader->load('deprecated_alias_definitions.yml');
182+
183+
$this->assertTrue($container->getAlias('alias_for_foobar')->isDeprecated());
184+
$message = 'The "alias_for_foobar" service alias is deprecated.';
185+
$this->assertSame($message, $container->getAlias('alias_for_foobar')->getDeprecationMessage('alias_for_foobar'));
186+
}
187+
177188
public function testLoadFactoryShortSyntax()
178189
{
179190
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)
0