Skip to content

Commit

Permalink
uses nette/php-generator 4.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 5, 2024
1 parent 4b5c716 commit 9b9bfb4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"ext-tokenizer": "*",
"ext-ctype": "*",
"nette/neon": "^3.3 || ^4.0",
"nette/php-generator": "^4.1.3",
"nette/php-generator": "^4.1.6",
"nette/robot-loader": "^4.0",
"nette/schema": "^1.2.5",
"nette/utils": "^4.0"
Expand Down
7 changes: 4 additions & 3 deletions src/DI/Extensions/ParametersExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class): void
});
}

$class->inheritMethod('getStaticParameters')
$manipulator = new Nette\PhpGenerator\ClassManipulator($class);
$manipulator->inheritMethod('getStaticParameters')
->addBody('return ?;', [array_diff_key($builder->parameters, $dynamicParams)]);

if (!$dynamicParams) {
Expand All @@ -70,7 +71,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class): void

$resolver = new Nette\DI\Resolver($builder);
$generator = new Nette\DI\PhpGenerator($builder);
$method = $class->inheritMethod('getDynamicParameter');
$method = $manipulator->inheritMethod('getDynamicParameter');
$method->addBody('return match($key) {');
foreach ($dynamicParams as $key => $foo) {
$value = Helpers::expand($this->config[$key] ?? null, $builder->parameters);
Expand All @@ -84,7 +85,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class): void
$method->addBody("\tdefault => parent::getDynamicParameter(\$key),\n};");

if ($preload = array_keys($dynamicParams, true, true)) {
$method = $class->inheritMethod('getParameters');
$method = $manipulator->inheritMethod('getParameters');
$method->addBody('array_map($this->getParameter(...), ?);', [$preload]);
$method->addBody('return parent::getParameters();');
}
Expand Down
7 changes: 4 additions & 3 deletions src/DI/PhpGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ public function generate(string $className): Php\ClassType
$this->className = $className;
$class = new Php\ClassType($this->className);
$class->setExtends(Container::class);
$class->inheritMethod('__construct')
$manipulator = new Php\ClassManipulator($class);
$manipulator->inheritMethod('__construct')
->addBody('parent::__construct($params);');

foreach ($this->builder->exportMeta() as $key => $value) {
$class->inheritProperty($key)
$manipulator->inheritProperty($key)
->setComment(null)
->setValue($value);
}
Expand All @@ -57,7 +58,7 @@ public function generate(string $className): Php\ClassType
$class->getMethod(Container::getMethodName(ContainerBuilder::ThisContainer))
->setBody('return $this;');

$class->inheritMethod('initialize');
$manipulator->inheritMethod('initialize');

return $class;
}
Expand Down

0 comments on commit 9b9bfb4

Please sign in to comment.