Cast result to int before adding to it
This fixes the occasional warning about non-numeric values when using PHP 7.1
This commit is contained in:
parent
ef40651dd3
commit
70c42f2676
@ -346,21 +346,22 @@ class XmlFileLoader extends FileLoader
|
|||||||
$arg->setAttribute('key', $arg->getAttribute('name'));
|
$arg->setAttribute('key', $arg->getAttribute('name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$arg->hasAttribute('key')) {
|
|
||||||
$key = !$arguments ? 0 : max(array_keys($arguments)) + 1;
|
|
||||||
} else {
|
|
||||||
$key = $arg->getAttribute('key');
|
|
||||||
}
|
|
||||||
|
|
||||||
// parameter keys are case insensitive
|
|
||||||
if ('parameter' == $name && $lowercase) {
|
|
||||||
$key = strtolower($key);
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is used by DefinitionDecorator to overwrite a specific
|
// this is used by DefinitionDecorator to overwrite a specific
|
||||||
// argument of the parent definition
|
// argument of the parent definition
|
||||||
if ($arg->hasAttribute('index')) {
|
if ($arg->hasAttribute('index')) {
|
||||||
$key = 'index_'.$arg->getAttribute('index');
|
$key = 'index_'.$arg->getAttribute('index');
|
||||||
|
} elseif (!$arg->hasAttribute('key')) {
|
||||||
|
// Append an empty argument, then fetch its key to overwrite it later
|
||||||
|
$arguments[] = null;
|
||||||
|
$keys = array_keys($arguments);
|
||||||
|
$key = array_pop($keys);
|
||||||
|
} else {
|
||||||
|
$key = $arg->getAttribute('key');
|
||||||
|
|
||||||
|
// parameter keys are case insensitive
|
||||||
|
if ('parameter' == $name && $lowercase) {
|
||||||
|
$key = strtolower($key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($arg->getAttribute('type')) {
|
switch ($arg->getAttribute('type')) {
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
<?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="foo" class="Foo">
|
||||||
|
<argument key="type">foo</argument>
|
||||||
|
<argument>bar</argument>
|
||||||
|
</service>
|
||||||
|
</services>
|
||||||
|
</container>
|
@ -542,4 +542,13 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame('Baz', $barConfigurator[0]->getClass());
|
$this->assertSame('Baz', $barConfigurator[0]->getClass());
|
||||||
$this->assertSame('configureBar', $barConfigurator[1]);
|
$this->assertSame('configureBar', $barConfigurator[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testArgumentWithKeyOutsideCollection()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
|
||||||
|
$loader->load('with_key_outside_collection.xml');
|
||||||
|
|
||||||
|
$this->assertSame(array('type' => 'foo', 'bar'), $container->getDefinition('foo')->getArguments());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user