Skip to content

Commit

Permalink
ParametersExtension: generates 'match'
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 23, 2023
1 parent e34ccb9 commit 57b0f2b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/DI/Extensions/ParametersExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
->setProtected()
->setReturnType('mixed');
$getter->addParameter('key')->setType('string|int');
$body = 'switch (true) {';
$body = 'return match($key) {';
foreach ($this->dynamicParams as $key => $foo) {
$value = Nette\DI\Helpers::expand($this->config[$key] ?? null, $builder->parameters);
$value = $resolver->completeArguments(Nette\DI\Helpers::filterArguments([$value]));
$body .= "\n\t" . 'case $key === ' . var_export($key, true) . ': return ' . $generator->formatPhp('?', $value) . ';';
$body .= "\n\t" . var_export($key, true) . ' => ' . $generator->formatPhp('?', $value) . ',';
}
$body .= "\n\t" . 'default: parent::getDynamicParameter($key);' . "\n};";
$body .= "\n\t" . 'default => parent::getDynamicParameter($key),' . "\n};";
$getter->addBody($body);

// dynamic parameters validation
Expand Down

0 comments on commit 57b0f2b

Please sign in to comment.