From 2ef048ccfbec010acf4ca6e8a0fc36c9dad1c7b5 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 21 Sep 2023 23:49:40 +0200 Subject: [PATCH] ParametersExtension: parameters with expressions are automatically treated as dynamic --- src/DI/Extensions/ParametersExtension.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/DI/Extensions/ParametersExtension.php b/src/DI/Extensions/ParametersExtension.php index b97dfa4ad..9f758fa8f 100644 --- a/src/DI/Extensions/ParametersExtension.php +++ b/src/DI/Extensions/ParametersExtension.php @@ -41,6 +41,16 @@ public function loadConfiguration() $resolver = new Nette\DI\Resolver($builder); $generator = new Nette\DI\PhpGenerator($builder); + // expressions are automatically treated as dynamic params + foreach ($params as $key => $value) { + $tmp = [$value]; + array_walk_recursive($tmp, function ($val) use ($key): void { + if ($val instanceof Nette\DI\Definitions\Statement) { + $this->dynamicParams[$key] = null; + } + }); + } + foreach ($this->dynamicParams as $key) { $params[$key] = array_key_exists($key, $params) ? new DynamicParameter($generator->formatPhp('($this->parameters[?] \?\? ?)', $resolver->completeArguments(Nette\DI\Helpers::filterArguments([$key, $params[$key]]))))