[DI] Rererence parameter arrays when possible
This commit is contained in:
parent
aef502b1a2
commit
62c1bb5d3b
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user