From 57b0f2bbae9eba788e808cd77451e6149eaeccd7 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 22 Sep 2023 00:08:39 +0200 Subject: [PATCH] ParametersExtension: generates 'match' --- src/DI/Extensions/ParametersExtension.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DI/Extensions/ParametersExtension.php b/src/DI/Extensions/ParametersExtension.php index 8534721e3..3b20f6b6f 100644 --- a/src/DI/Extensions/ParametersExtension.php +++ b/src/DI/Extensions/ParametersExtension.php @@ -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