8000 [DI] Rererence parameter arrays when possible · symfony/symfony@62c1bb5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 62c1bb5

Browse files
[DI] Rererence parameter arrays when possible
1 parent aef502b commit 62c1bb5

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,9 @@ private function hasReference($id, array $arguments, $deep = false, array &$visi
14301430
private function dumpValue($value, $interpolate = true)
14311431
{
14321432
if (is_array($value)) {
1433+
if ($value && $interpolate && false !== $param = array_search($value, $this->container->getParameterBag()->all(), true)) {
1434+
return $this->dumpValue("%$param%");
1435+
}
14331436
$code = array();
14341437
foreach ($value as $k => $v) {
14351438
$code[] = sprintf('%s => %s', $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate));

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ public function testArrayParameters()
607607
$container->setParameter('array_1', array(123));
608608
$container->setParameter('array_2', array(__DIR__));
609609
$container->register('bar', 'BarClass')
610-
->addMethodCall('setBaz', array('%array_1%', '%array_2%', '%%array_1%%'));
610+
->addMethodCall('setBaz', array('%array_1%', '%array_2%', '%%array_1%%', array(123)));
611611
$container->compile();
612612

613613
$dumper = new PhpDumper($container);

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function getBarService()
7575
{
7676
$this->services['bar'] = $instance = new \BarClass();
7777

78-
$instance->setBaz($this->parameters['array_1'], $this->getParameter('array_2'), '%array_1%');
78+
$instance->setBaz($this->parameters['array_1'], $this->getParameter('array_2'), '%array_1%', $this->parameters['array_1']);
7979

8080
return $instance;
8181
}

0 commit comments

Comments
 (0)
0