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 a208137

Browse filesBrowse files
committed
[DependencyInjection] Deprecate unsupported attributes/elements for alias
1 parent 307ad07 commit a208137
Copy full SHA for a208137

File tree

6 files changed

+63
-0
lines changed
Filter options

6 files changed

+63
-0
lines changed

‎src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ private function parseDefinitions(\DOMDocument $xml, $file)
132132
private function parseDefinition(\DOMElement $service, $file)
133133
{
134134
if ($alias = $service->getAttribute('alias')) {
135+
$this->validateAlias($service, $file);
136+
135137
$public = true;
136138
if ($publicAttr = $service->getAttribute('public')) {
137139
$public = XmlUtils::phpize($publicAttr);
@@ -490,6 +492,26 @@ public function validateSchema(\DOMDocument $dom)
490492
return $valid;
491493
}
492494

495+
/**
496+
* Validates an alias.
497+
*
498+
* @param \DOMElement
499+
*/
500+
private function validateAlias(\DOMElement $alias, $file)
501+
{
502+
foreach ($alias->attributes as $name => $node) {
503+
if (!in_array($name, array('alias', 'id', 'public'))) {
504+
@trigger_error(sprintf('Using the attribute "%s" is deprecated for alias definition "%s" in "%s". Allowed attributes are "alias", "id" and "public". The XmlFileLoader object will raise an exception instead in Symfony 4.0 when detecting an unsupported attribute.', $key, $alias->getAttribute('id'), $file), E_USER_DEPRECATED);
505+
}
506+
}
507+
508+
foreach ($alias->childNodes as $child) {
509+
if ($child instanceof \DOMElement && $child->namespaceURI === self::NS) {
510+
@trigger_error(sprintf('Using the element "%s" is deprecated for alias definition "%s" in "%s". The XmlFileLoader object will raise an exception instead in Symfony 4.0 when detecting an unsupported element.', $child->localName, $alias->getAttribute('id'), $file), E_USER_DEPRECATED);
511+
}
512+
}
513+
}
514+
493515
/**
494516
* Validates an extension.
495517
*

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ private function parseDefinition($id, $service, $file)
177177
$public = !array_key_exists('public', $service) || (bool) $service['public'];
178178
$this->container->setAlias($id, new Alias($service['alias'], $public));
179179

180+
foreach ($service as $key => $value) {
181+
if (!in_array($key, array('alias', 'public'))) {
182+
@trigger_error(sprintf('The configuration key "%s" is unsupported for alias definition "%s" in "%s". Allowed configuration keys are "alias" and "public". The YamlFileLoader object will raise an exception instead in Symfony 4.0 when detecting an unsupported service configuration key.', $key, $id, $file), E_USER_DEPRECATED);
183+
}
184+
}
185+
180186
return;
181187
}
182188

+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<services>
4+
<service id="foo" class="Foo" />
5+
6+
<service id="bar" alias="foo" class="Foo">
7+
<tag name="foo.bar" />
8+
</service>
9+
</services>
10+
</container>
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
foo:
3+
alias: bar
4+
factory: foo
5+
parent: quz

‎src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,14 @@ public function testAutowire()
486486

487487
$this->assertTrue($container->getDefinition('bar')->isAutowired());
488488
}
489+
490+
/**
491+
* @group legacy
492+
*/
493+
public function testAliasDefinitionContainsUnsupportedElements()
494+
{
495+
$container = new ContainerBuilder();
496+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
497+
$loader->load('legacy_invalid_alias_definition.xml');
498+
}
489499
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,14 @@ public function testServiceDefinitionContainsUnsupportedKeywords()
303303
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
304304
$loader->load('legacy_invalid_definition.yml');
305305
}
306+
307+
/**
308+
* @group legacy
309+
*/
310+
public function testAliasDefinitionContainsUnsupportedKeywords()
311+
{
312+
$container = new ContainerBuilder();
313+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
314+
$loader->load('legacy_invalid_alias_definition.yml');
315+
}
306316
}

0 commit comments

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