aboutsummaryrefslogtreecommitdiff
path: root/lib/exTpl/ExpressionNode.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/exTpl/ExpressionNode.php')
-rw-r--r--lib/exTpl/ExpressionNode.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/exTpl/ExpressionNode.php b/lib/exTpl/ExpressionNode.php
new file mode 100644
index 0000000..061edce
--- /dev/null
+++ b/lib/exTpl/ExpressionNode.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace exTpl;
+
+/**
+ * ExpressionNode represents an expression tag: "{...}".
+ */
+class ExpressionNode implements Node
+{
+ protected Expression $expr;
+
+ /**
+ * Initializes a new Node instance with the given expression.
+ *
+ * @param Expression $expr expression object
+ */
+ public function __construct(Expression $expr)
+ {
+ $this->expr = $expr;
+ }
+
+ /**
+ * Returns a string representation of this node.
+ *
+ * @param Context $context symbol table
+ */
+ public function render(Context $context): ?string
+ {
+ $value = $this->expr->value($context);
+
+ if (!($this->expr instanceof RawExpression)) {
+ $value = $context->escape($value);
+ }
+
+ return $value;
+ }
+}