[DI] Rererence parameter arrays when possible

This commit is contained in:
Nicolas Grekas 2017-08-17 11:23:46 +02:00
parent aef502b1a2
commit 62c1bb5d3b
3 changed files with 5 additions and 2 deletions

View File

@ -1430,6 +1430,9 @@ EOF;
private function dumpValue($value, $interpolate = true)
{
if (is_array($value)) {
if ($value && $interpolate && false !== $param = array_search($value, $this->container->getParameterBag()->all(), true)) {
return $this->dumpValue("%$param%");
}
$code = array();
foreach ($value as $k => $v) {
$code[] = sprintf('%s => %s', $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate));

View File

@ -607,7 +607,7 @@ class PhpDumperTest extends TestCase
$container->setParameter('array_1', array(123));
$container->setParameter('array_2', array(__DIR__));
$container->register('bar', 'BarClass')
->addMethodCall('setBaz', array('%array_1%', '%array_2%', '%%array_1%%'));
->addMethodCall('setBaz', array('%array_1%', '%array_2%', '%%array_1%%', array(123)));
$container->compile();
$dumper = new PhpDumper($container);

View File

@ -75,7 +75,7 @@ class ProjectServiceContainer extends Container
{
$this->services['bar'] = $instance = new \BarClass();
$instance->setBaz($this->parameters['array_1'], $this->getParameter('array_2'), '%array_1%');
$instance->setBaz($this->parameters['array_1'], $this->getParameter('array_2'), '%array_1%', $this->parameters['array_1']);
return $instance;
}