- Added support fort named parameters in block calls

This commit is contained in:
Dave M. 2026-01-09 16:03:53 -05:00
parent c975de0557
commit 210c8ae0bd

View File

@ -129,18 +129,27 @@ class BlockToken implements ControlStructure {
$parameters = []; $parameters = [];
foreach((new \ReflectionFunction($method))->getParameters() as $key => $value) { foreach((new \ReflectionFunction($method))->getParameters() as $key => $value) {
$name = $value->getName();
# Ordered arguments
if ( isset($arguments[$key]) ) { if ( isset($arguments[$key]) ) {
$parameters[ $value->getName() ] = $arguments[$key]; $parameters[ $name ] = $arguments[$key];
} }
# Named arguments
elseif (isset($arguments[$name])) {
$parameters[ $name ] = $arguments[$name];
}
# Using default value
elseif ( $value->isDefaultValueAvailable() ) { elseif ( $value->isDefaultValueAvailable() ) {
$parameters[ $value->getName() ] = $value->getDefaultValue(); $parameters[ $name ] = $value->getDefaultValue();
} }
elseif ( $value->isVariadic() ) { elseif ( $value->isVariadic() ) {
$parameters[ $value->getName() ] = []; $parameters[ $name ] = [];
} }
else { else {
$parameters[ $value->getName() ] = null; $parameters[ $name ] = null;
} }
} }
@ -232,7 +241,7 @@ class BlockToken implements ControlStructure {
throw new \InvalidArgumentException("Block '{$this->viewPath}' cannot overwrite 'this' variable."); throw new \InvalidArgumentException("Block '{$this->viewPath}' cannot overwrite 'this' variable.");
} }
return $classTemplate->picea->inlineBlock($thisProxy ?? $this, $this->viewPath, ...$this->arguments); return $classTemplate->picea->inlineBlock($this, $this->viewPath, ...$this->arguments);
} }
public function setSlot(string $name, Callable $method) : void public function setSlot(string $name, Callable $method) : void