- Fixed a bug that appeared deeper when rendering a block inside the slot of another block
This commit is contained in:
parent
934643214e
commit
d22d26c9c8
|
@ -8,15 +8,20 @@ class BlockToken implements ControlStructure {
|
||||||
|
|
||||||
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
|
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
|
||||||
{
|
{
|
||||||
|
static $depth = 0;
|
||||||
static $slotDefinitions = [];
|
static $slotDefinitions = [];
|
||||||
|
|
||||||
|
# dump($depth, $token, $arguments, $slotDefinitions);
|
||||||
|
|
||||||
switch($token) {
|
switch($token) {
|
||||||
case "block":
|
case "block":
|
||||||
$slotDefinitions[] = $this->slotDefinitions();
|
$slotDefinitions[] = $this->slotDefinitions();
|
||||||
|
$depth++;
|
||||||
|
|
||||||
return "<?php \$___block = \Picea\ControlStructure\BlockToken::instanciateBlock($arguments); ?>";
|
return "<?php \$___block = \Picea\ControlStructure\BlockToken::instanciateBlock($arguments); ?>";
|
||||||
|
|
||||||
case "endblock":
|
case "endblock":
|
||||||
|
$depth--;
|
||||||
return "<?php echo \$___block->render(\$___class__template); unset(\$___block); ?>";
|
return "<?php echo \$___block->render(\$___class__template); unset(\$___block); ?>";
|
||||||
|
|
||||||
case "arguments":
|
case "arguments":
|
||||||
|
@ -40,14 +45,14 @@ class BlockToken implements ControlStructure {
|
||||||
case "define":
|
case "define":
|
||||||
list($name, $definition) = array_pad(explode(',', $arguments, 2), 2, "");
|
list($name, $definition) = array_pad(explode(',', $arguments, 2), 2, "");
|
||||||
|
|
||||||
end($slotDefinitions)->setDefinition(eval("return $name;"), $definition);
|
( $slotDefinitions[$depth] ?? end($slotDefinitions) )->setDefinition(eval("return $name;"), $definition);
|
||||||
|
|
||||||
return <<<PHP
|
return <<<PHP
|
||||||
<?php \$this->defineSlot($name, function($definition) {}); ?>
|
<?php \$this->defineSlot($name, function($definition) {}); ?>
|
||||||
PHP;
|
PHP;
|
||||||
|
|
||||||
case "slot":
|
case "slot":
|
||||||
$def = end($slotDefinitions);
|
$def = ( $slotDefinitions[$depth] ?? end($slotDefinitions) );
|
||||||
|
|
||||||
list($name, $definition) = array_pad(explode(',', $arguments, 2), 2, "");
|
list($name, $definition) = array_pad(explode(',', $arguments, 2), 2, "");
|
||||||
|
|
||||||
|
@ -74,12 +79,12 @@ class BlockToken implements ControlStructure {
|
||||||
}
|
}
|
||||||
|
|
||||||
return <<<PHP
|
return <<<PHP
|
||||||
<?php (\$___block ?? \$this)->slotIsSet($name) || \$___block->setSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?>
|
<?php (\$___block ?? \$this)->slotIsSet($name) || (\$___block ?? \$this)->setSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?>
|
||||||
PHP;
|
PHP;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "endslot":
|
case "endslot":
|
||||||
$def =end($slotDefinitions);
|
$def = ( $slotDefinitions[$depth] ?? end($slotDefinitions) );
|
||||||
|
|
||||||
if ($def->hasDefinitions() ) {
|
if ($def->hasDefinitions() ) {
|
||||||
$definition = $def->getCurrentSlotDefinitionVars();
|
$definition = $def->getCurrentSlotDefinitionVars();
|
||||||
|
|
Loading…
Reference in New Issue