From 62c1bb5d3b20c9b1b7904f494c7da4c9cd688241 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 17 Aug 2017 11:23:46 +0200 Subject: [PATCH] [DI] Rererence parameter arrays when possible --- src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php | 3 +++ .../DependencyInjection/Tests/Dumper/PhpDumperTest.php | 2 +- .../Tests/Fixtures/php/services_array_params.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index cdcea02ed1..52a9f8aca8 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -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)); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index fc5a950af4..e60ee91cdd 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -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); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php index 92db92cc4e..b8d52d69f5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_array_params.php @@ -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; }