aboutsummaryrefslogtreecommitdiff
path: root/lib/exTpl/ExpressionNode.php
blob: 061edce2497e3ae1ce7882aa3adc0633dd7a826c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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;
    }
}