lollipop

A PHP-framework
Log | Files | Refs

commit 404129eee26afc3387b6a23f6df13ba729d767b2
parent fa11251b474626b5d570cee37daeb11aaf09139a
Author: Friedel Schön <[email protected]>
Date:   Tue, 30 May 2023 16:55:25 +0200

add template-include template-eval

Diffstat:
MLollipop/Template.php | 40++++++++++++++++++++++++++++++++++++----
Mtemplate_test.html | 7++++++-
Atest_include.php | 6++++++
3 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/Lollipop/Template.php b/Lollipop/Template.php @@ -63,10 +63,7 @@ use ErrorException; if ($left == null || $right == null) throw new ErrorException("Stack is empty"); - if (is_numeric($left) && is_numeric($right)) - return intval($left) + intval($right); - - return $left . $right; + return $left + $right; }, "sub" => function(array &$tokens) { $right = array_pop($tokens); @@ -95,6 +92,41 @@ use ErrorException; return intval($left) / intval($right); }, + "cat" => function(array &$tokens) { + $right = array_pop($tokens); + $left = array_pop($tokens); + + if ($left == null || $right == null) + throw new ErrorException("Stack is empty"); + + return $left . $right; + }, + + "to_int" => function(array &$tokens) { + $val = array_pop($val); + + if ($val == null) + throw new ErrorException("Stack is empty"); + + return inval($val); + }, + + "include" => function (array &$tokens) { + $name = array_pop($tokens); + + if (!$name) + throw new ErrorException("Stack is empty"); + + include($name); + }, + "eval" => function (array &$tokens) { + $expr = array_pop($tokens); + + if (!$expr) + throw new ErrorException("Stack is empty"); + + return eval("return ($expr);"); + } ]; $stack = []; diff --git a/template_test.html b/template_test.html @@ -1 +1,5 @@ -data: {{ 3 !add }} +{{ name "value" !set }} + +{{ "test_include.php" !include }} + +{{ "hello_foo()" !eval "- Mayor Monogram" !cat }} +\ No newline at end of file diff --git a/test_include.php b/test_include.php @@ -0,0 +1,5 @@ +<?php + +function hello_foo() { + return "HELLO FOO"; +} +\ No newline at end of file