<?php

namespace Application\Service\Extension\Expression\Node;

use Symfony\Component\ExpressionLanguage\Compiler;
use Symfony\Component\ExpressionLanguage\Node\Node;

class NameNode extends Node
{
    public function __construct(string $name)
    {
        parent::__construct(
            [],
            ['name' => $name]
        );
    }

    public function compile(Compiler $compiler)
    {
        $compiler->raw('$'.$this->attributes['name']);
    }

    public function evaluate(array $functions, array $values)
    {
        return $values[$this->attributes['name']] ?? '';
    }

    public function toArray()
    {
        return [$this->attributes['name']];
    }
}