1<?php
2
3/*
4 * This file is part of Twig.
5 *
6 * (c) Fabien Potencier
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12class SimpleTokenParser extends Twig_Extensions_SimpleTokenParser
13{
14    protected $tag;
15    protected $grammar;
16
17    public function __construct($tag, $grammar)
18    {
19        $this->tag = $tag;
20        $this->grammar = $grammar;
21    }
22
23    public function getGrammar()
24    {
25        return $this->grammar;
26    }
27
28    public function getTag()
29    {
30        return $this->tag;
31    }
32
33    public function getNode(array $values, $line)
34    {
35        $nodes = array();
36        $nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant('|', $line), $line);
37        foreach ($values as $value) {
38            if ($value instanceof Twig_Node) {
39                if ($value instanceof Twig_Node_Expression_Array) {
40                    $nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Function('dump', $value, $line), $line);
41                } else {
42                    $nodes[] = new Twig_Node_Print($value, $line);
43                }
44            } else {
45                $nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant($value, $line), $line);
46            }
47            $nodes[] = new Twig_Node_Print(new Twig_Node_Expression_Constant('|', $line), $line);
48        }
49
50        return new Twig_Node($nodes);
51    }
52}
53