aboutsummaryrefslogtreecommitdiff
path: root/lib/exTpl/SymbolExpression.php
blob: 178a51f0a3c20e891e9a5b41c368bd5ea0251a4f (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
38
39
<?php

namespace exTpl;

/**
 * SymbolExpression represents a symbol (template variable).
 */
class SymbolExpression implements Expression
{
    protected string $name;

    /**
     * Initializes a new Expression instance.
     *
     * @param string $name      symbol name
     */
    public function __construct(string $name)
    {
        $this->name = $name;
    }

    /**
     * Returns the name of this symbol.
     */
    public function name(): string
    {
        return $this->name;
    }

    /**
     * Returns the value of this expression.
     *
     * @param Context $context  symbol table
     */
    public function value(Context $context): mixed
    {
        return $context->lookup($this->name);
    }
}