8000 minor #23912 [DI] Rererence parameter arrays when possible (nicolas-g… · symfony/symfony@9306fec · GitHub
[go: up one dir, main page]

Skip to content

Commit 9306fec

Browse files
committed
minor #23912 [DI] Rererence parameter arrays when possible (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [DI] Rererence parameter arrays when possible | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no (perf optim) | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - This a minor optim that might save memory and CPU for cases where big array parameters are inlined by DI extensions. This re-references them when possible. Commits ------- 62c1bb5 [DI] Rererence parameter arrays when possible
2 parents 16d34eb + 62c1bb5 commit 9306fec

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