- Block can now reference a 'this' object from it's {% using [ 'this' => new stdClass() ] %} token

- Fixed a bug with {% use %} which was buggy whenever two uses were declared and one of them had a curly braces notation in it.
This commit is contained in:
Dave Mc Nicoll 2024-10-21 18:09:33 +00:00
parent 7970679894
commit 35a7bd4cf7
3 changed files with 8 additions and 3 deletions

View File

@ -21,7 +21,7 @@ class Builder
$replace = [
'%NAMESPACE%' => $context->namespace,
'%USE%' => ( $uses = $context->renderUses() ) ? "use $uses;" : false,
'%USE%' => ( $uses = $context->renderUses() ) ? $uses : false,
'%CLASSNAME%' => $context->className,
'%PATHNAME%' => $path($context->viewPath),
'%FULLPATH%' => $path($context->filePath),

View File

@ -57,7 +57,7 @@ abstract class Context {
public function renderUses() : string
{
return implode(",", $this->useStack ?? []);
return implode(PHP_EOL, array_map(fn($use) => "use $use;", $this->useStack ?? []));
}
public function renderFunctions() : string

View File

@ -227,7 +227,12 @@ class BlockToken implements ControlStructure {
{
$this->rendering = true;
return $classTemplate->picea->inlineBlock($this, $this->viewPath, ...$this->arguments);
if ($this->using['this'] ?? false) {
$thisProxy = $this->using['this'];
unset($this->using['this']);
}
return $classTemplate->picea->inlineBlock($thisProxy ?? $this, $this->viewPath, ...$this->arguments);
}
public function setSlot(string $name, Callable $method) : void