diff --git a/src/DI/Helpers.php b/src/DI/Helpers.php index 9e20c5434..3384a3408 100644 --- a/src/DI/Helpers.php +++ b/src/DI/Helpers.php @@ -34,7 +34,11 @@ public static function expand($var, array $params, $recursive = false) if (is_array($var)) { $res = []; foreach ($var as $key => $val) { - $res[$key] = self::expand($val, $params, $recursive); + if (is_int($key) && is_string($val) && preg_match('#^\.\.\.(%[\w.-]*%)\z#i', $val, $matches)) { + $res = array_merge($res, self::expand($matches[1], $params, $recursive)); + } else { + $res[$key] = self::expand($val, $params, $recursive); + } } return $res; diff --git a/tests/DI/Compiler.parameters.spread.phpt b/tests/DI/Compiler.parameters.spread.phpt new file mode 100644 index 000000000..234d12ffc --- /dev/null +++ b/tests/DI/Compiler.parameters.spread.phpt @@ -0,0 +1,56 @@ +config = $config; + } +} + + +$container = createContainer(new DI\Compiler, ' +parameters: + connection: + username: root + password: 123 + connection2: + - ...%connection% + database: app +services: + connection: DbConnection([timezone: utc, ...%connection2%]) + '); + + +Assert::same([ + 'username' => 'root', + 'password' => 123, + 'database' => 'app', +], $container->getParameters()['connection2']); + +/** @var DbConnection $connection */ +$connection = $container->getService('connection'); +Assert::same([ + 'timezone' => 'utc', + 'username' => 'root', + 'password' => 123, + 'database' => 'app', +], $connection->config);