- Fixed ViewToken and BlockToken inline vars

This commit is contained in:
Dave Mc Nicoll committed 2020-11-27 11:32:01 -05:00
1 parent 082bdd4ad3
commit 82eca2e520
7 files changed
+37 -39

No files matched your search

+13 -5
View File
@@ -55,13 +55,21 @@ class BlockToken implements ControlStructure {
$definition = $def->printDefinition($slotName);
if ($definition) {
$definition .= ",";
}
return <<<PHP
<?php \$this->printSlot($name, function($definition, array \$___using = []) { extract(\$___using, \EXTR_SKIP); ?>
<?php \$this->printSlot($name, function($definition array \$___using = []) use (\$picea) { extract(\$___using, \EXTR_SKIP); ?>
PHP;
}
else {
if ($definition) {
$definition .= ",";
}
return <<<PHP
<?php \$___block->slotIsSet($name) || \$___block->setSlot($name, function($definition, array \$___using = []) { extract(\$___using, \EXTR_SKIP); ?>
<?php \$___block->slotIsSet($name) || \$___block->setSlot($name, function($definition array \$___using = []) use (\$picea) { extract(\$___using, \EXTR_SKIP); ?>
PHP;
}
@@ -72,11 +80,11 @@ class BlockToken implements ControlStructure {
$definition = $def->getCurrentSlotDefinitionVars();
if ($definition) {
$definition = "$definition,";
$definition .= ",";
}
return <<<PHP
<?php })->call(\$this, $definition \$this->using); ?>
<?php })->call(\$this, $definition array_merge(get_defined_vars(), \$this->using)); ?>
PHP;
}
else {
@@ -207,7 +215,7 @@ class BlockToken implements ControlStructure {
{
$this->rendering = true;
return $classTemplate->picea->inlineHtml($this, $this->viewPath, ...$this->arguments);
return $classTemplate->picea->inlineBlock($this, $this->viewPath, ...$this->arguments);
}
public function setSlot(string $name, Callable $method) : void
+2 -1
View File
@@ -7,6 +7,7 @@ class ViewToken implements ControlStructure {
public string $token = "view";
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
return "<?php echo \$___class__template->picea->renderHtml($arguments, get_defined_vars(), \$this); ?>";
# The way this is ordered, if you provide a second arguments, being an array of variables, get_defined_vars() will not be pushed inside the view
return "<?php echo \$___class__template->picea->inlineHtml(\$this, $arguments, get_defined_vars()); ?>";
}
}