minor #20180 Improved the deprecation messages for service aliases (javiereguiluz)

This PR was squashed before being merged into the 3.1 branch (closes #20180).

Discussion
----------

Improved the deprecation messages for service aliases

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19832
| License       | MIT
| Doc PR        |

Commits
-------

b1b21bf Improved the deprecation messages for service aliases
This commit is contained in:
Fabien Potencier 2016-10-07 15:26:03 -07:00
commit 98e627a7af
3 changed files with 6 additions and 6 deletions

View File

@ -505,13 +505,13 @@ EOF
{
foreach ($alias->attributes as $name => $node) {
if (!in_array($name, array('alias', 'id', 'public'))) {
@trigger_error(sprintf('Using the attribute "%s" is deprecated for alias definition "%s" in "%s". Allowed attributes are "alias", "id" and "public". The XmlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported attributes.', $name, $alias->getAttribute('id'), $file), E_USER_DEPRECATED);
@trigger_error(sprintf('Using the attribute "%s" is deprecated for the service "%s" which is defined as an alias in "%s". Allowed attributes for service aliases are "alias", "id" and "public". The XmlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported attributes.', $name, $alias->getAttribute('id'), $file), E_USER_DEPRECATED);
}
}
foreach ($alias->childNodes as $child) {
if ($child instanceof \DOMElement && $child->namespaceURI === self::NS) {
@trigger_error(sprintf('Using the element "%s" is deprecated for alias definition "%s" in "%s". The XmlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported elements.', $child->localName, $alias->getAttribute('id'), $file), E_USER_DEPRECATED);
@trigger_error(sprintf('Using the element "%s" is deprecated for the service "%s" which is defined as an alias in "%s". The XmlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported elements.', $child->localName, $alias->getAttribute('id'), $file), E_USER_DEPRECATED);
}
}
}

View File

@ -180,7 +180,7 @@ class YamlFileLoader extends FileLoader
foreach ($service as $key => $value) {
if (!in_array($key, array('alias', 'public'))) {
@trigger_error(sprintf('The configuration key "%s" is unsupported for alias definition "%s" in "%s". Allowed configuration keys 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);
@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);
}
}

View File

@ -563,9 +563,9 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
public function testAliasDefinitionContainsUnsupportedElements()
{
$deprecations = array(
'Using the attribute "class" is deprecated for alias definition "bar"',
'Using the element "tag" is deprecated for alias definition "bar"',
'Using the element "factory" is deprecated for alias definition "bar"',
'Using the attribute "class" is deprecated for the service "bar" which is defined as an alias',
'Using the element "tag" is deprecated for the service "bar" which is defined as an alias',
'Using the element "factory" is deprecated for the service "bar" which is defined as an alias',
);
ErrorAssert::assertDeprecationsAreTriggered($deprecations, function () {