diff --git a/docs/99-dependency-injection.md b/docs/99-dependency-injection.md index 70823a5..fb1e70e 100644 --- a/docs/99-dependency-injection.md +++ b/docs/99-dependency-injection.md @@ -7,7 +7,7 @@ It also insert `Tell` inside the LanguageHandler which handles the `{% _ 'relati ```php use function DI\autowire, DI\create, DI\get; -use Zend\Diactoros\Response\HtmlResponse; +use Laminas\Diactoros\Response\HtmlResponse; use Picea\{ Picea, Caching\Cache, Caching\Opcache, Compiler, Compiler\Context, Compiler\BaseContext, FileFetcher, Language\DefaultRegistrations, Method\Request }; use Picea\Extension\{ LanguageHandler, LanguageExtension, TitleExtension, MoneyExtension, UrlExtension }; diff --git a/src/Compiler/Context.php b/src/Compiler/Context.php index b490c40..1fbe3e3 100644 --- a/src/Compiler/Context.php +++ b/src/Compiler/Context.php @@ -14,6 +14,8 @@ abstract class Context { public string $compiledSource = ""; + public ? string $sectionAction = null; + public string $viewPath = ""; public string $filePath = ""; diff --git a/src/ControlStructure/SectionToken.php b/src/ControlStructure/SectionToken.php index 1da7f68..b930345 100644 --- a/src/ControlStructure/SectionToken.php +++ b/src/ControlStructure/SectionToken.php @@ -4,13 +4,17 @@ namespace Picea\ControlStructure; class SectionToken implements ControlStructure { - public array $token = [ "section", "endsection" ]; + public array $token = [ "section", "section.prepend", "section.append", "endsection" ]; public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token) { switch($token) { + case "section.prepend": + $context->sectionAction = "prepend"; + case "section.append": + $context->sectionAction ??= "append"; case "section": return $this->printSection($context, $arguments); - + case "endsection": if ( empty($context->sections) ) { throw new \RuntimeException("A section closing tag {% endsection %} was found without an opening {% section %} tag"); @@ -28,7 +32,7 @@ class SectionToken implements ControlStructure { $options = eval("return $options;"); } - if ( ! ctype_alnum(str_replace([".", "\"", "'", "-", "_"], "", $name)) ) { + if ( ! ctype_alnum(str_replace([".", "\"", "'", "-", "_", ":"], "", $name)) ) { throw new \RuntimeException("Your section named `{$name}` contains invalid character. Allowed are only letters, numbers, dashes, underscores and dots"); } @@ -37,7 +41,9 @@ class SectionToken implements ControlStructure { 'options' => $options, ]; - $action = $options['action'] ?? "default"; + $action = $options['action'] ?? $context->sectionAction ?? "default"; + + unset($context->sectionAction); if (! in_array($action, ['prepend', 'append', 'default'])) { throw new \RuntimeException("An unsupported action `$action` was given as an option of a {% section %} tag");