- Added support fort named parameters in block calls
This commit is contained in:
parent
c975de0557
commit
210c8ae0bd
@ -129,18 +129,27 @@ class BlockToken implements ControlStructure {
|
||||
|
||||
$parameters = [];
|
||||
|
||||
|
||||
foreach((new \ReflectionFunction($method))->getParameters() as $key => $value) {
|
||||
$name = $value->getName();
|
||||
|
||||
# Ordered arguments
|
||||
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() ) {
|
||||
$parameters[ $value->getName() ] = $value->getDefaultValue();
|
||||
$parameters[ $name ] = $value->getDefaultValue();
|
||||
}
|
||||
elseif ( $value->isVariadic() ) {
|
||||
$parameters[ $value->getName() ] = [];
|
||||
$parameters[ $name ] = [];
|
||||
}
|
||||
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.");
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user