Skip to content

Commit

Permalink
getParameters() WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 27, 2023
1 parent 955017f commit 25e9a78
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/DI/Extensions/ParametersExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
}

$getter = $class->addMethod('getDynamicParameter')->setProtected();
$getterAll = $class->addMethod('getParameters')->setReturnType('array');
$getter->addParameter('key');
$resolver = new Nette\DI\Resolver($builder);
$generator = new Nette\DI\PhpGenerator($builder);
Expand All @@ -93,8 +94,10 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
$value = Nette\DI\Helpers::expand($this->config[$key] ?? null, $builder->parameters);
$value = $resolver->completeArguments(Nette\DI\Helpers::filterArguments([$value]));
$getter->addBody("\tcase \$key === ?: return ?;", [$key, $generator->convertArguments($value)[0]]);
$getterAll->addBody("$this->getParameter(?);", [$key]);
}
$getter->addBody("\tdefault: parent::getDynamicParameter(\$key);\n};");
$getterAll->addBody('return parent::getParameters();');

foreach ($this->dynamicValidators as [$param, $expected]) {
$this->initialization->addBody('Nette\Utils\Validators::assert(?, ?, ?);', [$param, $expected, 'dynamic parameter']);
Expand Down

0 comments on commit 25e9a78

Please sign in to comment.