bug #10629 [DependencyInjection] Fix #10626, use better check on attribute existence and values on XML load (romainneutron)
This PR was merged into the 2.5-dev branch.
Discussion
----------
[DependencyInjection] Fix #10626, use better check on attribute existence and values on XML load
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #10626
| License | MIT
Commits
-------
8163427
[DependencyInjection] Fix #10626, use better check on attribute existence and values on XML load
This commit is contained in:
commit
bc6020d8d7
@ -307,12 +307,14 @@ class XmlFileLoader extends FileLoader
|
||||
{
|
||||
$arguments = array();
|
||||
foreach ($this->getChildren($node, $name) as $arg) {
|
||||
if ($nameAttr = $arg->getAttribute('name')) {
|
||||
$arg->setAttribute('key', $nameAttr);
|
||||
if ($arg->hasAttribute('name')) {
|
||||
$arg->setAttribute('key', $arg->getAttribute('name'));
|
||||
}
|
||||
|
||||
if (!$key = $arg->getAttribute('key')) {
|
||||
if (!$arg->hasAttribute('key')) {
|
||||
$key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
|
||||
} else {
|
||||
$key = $arg->getAttribute('key');
|
||||
}
|
||||
|
||||
// parameter keys are case insensitive
|
||||
@ -322,8 +324,8 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
// this is used by DefinitionDecorator to overwrite a specific
|
||||
// argument of the parent definition
|
||||
if ($index = $arg->getAttribute('index')) {
|
||||
$key = 'index_'.$index;
|
||||
if ($arg->hasAttribute('index')) {
|
||||
$key = 'index_'.$arg->getAttribute('index');
|
||||
}
|
||||
|
||||
switch ($arg->getAttribute('type')) {
|
||||
|
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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">
|
||||
<services>
|
||||
<service id="monolog.logger" parent="monolog.logger_prototype" public="false">
|
||||
<argument index="0">app</argument>
|
||||
</service>
|
||||
|
||||
<service id="logger" alias="monolog.logger" />
|
||||
|
||||
<service id="monolog.logger" parent="monolog.logger_prototype" public="false">
|
||||
<argument index="0">app</argument>
|
||||
</service>
|
||||
<service id="monolog.logger_prototype" class="Symfony\Bridge\Monolog\Logger" abstract="true">
|
||||
<argument /><!-- Channel -->
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
@ -444,4 +444,13 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(1, count($services['foo']->getTag('foo.tag')), '->load parses <srv:tag> elements');
|
||||
$this->assertEquals(array(array('setBar', array('foo'))), $services['foo']->getMethodCalls(), '->load() parses the <srv:call> tag');
|
||||
}
|
||||
|
||||
public function testLoadIndexedArguments()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
|
||||
$loader->load('services14.xml');
|
||||
|
||||
$this->assertEquals(array('index_0' => 'app'), $container->findDefinition('logger')->getArguments());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user