Skip to content

Commit

Permalink
ParametersExtension: parameters with expressions are automatically tr…
Browse files Browse the repository at this point in the history
…eated as dynamic
  • Loading branch information
dg committed Sep 21, 2023
1 parent 5cffb51 commit 2ef048c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/DI/Extensions/ParametersExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]]))))
Expand Down

0 comments on commit 2ef048c

Please sign in to comment.