From 48ecd9f7d95b07441e59428caa4347ba199d270e Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Fri, 3 Jun 2022 15:30:16 +0000 Subject: [PATCH] - Made some bugfixes regarding blocks and slots --- src/ControlStructure/BlockToken.php | 12 +++++++----- src/ControlStructure/SectionToken.php | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ControlStructure/BlockToken.php b/src/ControlStructure/BlockToken.php index 3ee235b..f02787e 100644 --- a/src/ControlStructure/BlockToken.php +++ b/src/ControlStructure/BlockToken.php @@ -24,14 +24,13 @@ class BlockToken implements ControlStructure { return <<using ?? [], \EXTR_OVERWRITE); extract( \\$class::parseArguments(function($arguments) {}, \$inlineVariables), \EXTR_OVERWRITE); - unset(\$inlineVariables); } catch(\TypeError \$ex) { - throw new \Exception( - sprintf('A block awaiting arguments `%s` instead received `%s` with values `%s`', '$arguments', implode(', ', array_map('gettype', \$inlineVariables)), json_encode(\$inlineVariables)) + sprintf('A block awaiting arguments `%s` instead received `%s` with values `%s`', '$arguments', implode(', ', array_map('gettype', \$inlineVariables)), json_encode(\$inlineVariables)) ); } ?> @@ -72,7 +71,7 @@ class BlockToken implements ControlStructure { } return <<slotIsSet($name) || \$___block->setSlot($name, function($definition array \$___using = []) use (\$picea) { extract(\$___using, \EXTR_SKIP); ?> + slotIsSet($name) || \$___block->setSlot($name, function($definition array \$___using = []) use (\$picea) { extract(\$___using, \EXTR_SKIP); ?> PHP; } @@ -131,6 +130,9 @@ class BlockToken implements ControlStructure { elseif ( $value->isVariadic() ) { $parameters[ $value->getName() ] = []; } + else { + $parameters[ $value->getName() ] = null; + } } return $parameters; @@ -217,7 +219,7 @@ class BlockToken implements ControlStructure { public function render(object $classTemplate) : string { $this->rendering = true; - + return $classTemplate->picea->inlineBlock($this, $this->viewPath, ...$this->arguments); } diff --git a/src/ControlStructure/SectionToken.php b/src/ControlStructure/SectionToken.php index 08543ad..127521f 100644 --- a/src/ControlStructure/SectionToken.php +++ b/src/ControlStructure/SectionToken.php @@ -53,7 +53,7 @@ class SectionToken implements ControlStructure { protected function printEndSection($context) : string { $section = array_pop($context->sections); - $build = $context->extendFrom ? "\$___class__template->sectionStack && \$___class__template->renderSection({$section['name']});" : "\$___class__template->renderSection({$section['name']});"; + $build = $context->extendFrom ? "!empty(\$___class__template->sectionStack) && \$___class__template->renderSection({$section['name']});" : "\$___class__template->renderSection({$section['name']});"; return "sectionStack); }]; $build?>"; } } \ No newline at end of file