1 | <?php |
||
11 | use Twig\Node\Node as Twig_Node; |
||
12 | use Twig\Node\TextNode as Twig_Node_Text; |
||
13 | |||
14 | /** |
||
15 | * Class SyntaxCheckNodeVisitor. |
||
16 | */ |
||
17 | class SyntaxCheckNodeVisitor extends Twig_BaseNodeVisitor |
||
18 | { |
||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $path = []; |
||
23 | |||
24 | /** |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | public function getPriority() |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | * |
||
35 | * @throws Twig_Error_Syntax |
||
36 | */ |
||
37 | protected function doEnterNode(Twig_Node $node, Twig_Environment $env) |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) |
||
65 | |||
66 | /** |
||
67 | * @param Twig_Node $node |
||
68 | * |
||
69 | * @throws Twig_Error_Syntax |
||
70 | */ |
||
71 | private function checkAllowedChildren(Twig_Node $node) |
||
93 | |||
94 | /** |
||
95 | * @param BaseNode $node |
||
96 | * |
||
97 | * @throws Twig_Error_Syntax |
||
98 | */ |
||
99 | private function checkAllowedParents(BaseNode $node) |
||
100 | { |
||
101 | $parentName = null; |
||
102 | |||
103 | // find first parent from this bundle |
||
104 | foreach (array_reverse($this->path) as $className) { |
||
105 | if (strpos($className, 'Erelke\\TwigSpreadsheetBundle\\Twig\\Node\\') === 0) { |
||
106 | $parentName = $className; |
||
107 | break; |
||
108 | } |
||
109 | } |
||
110 | |||
111 | // allow no parents (e.g. macros, includes) |
||
112 | if ($parentName === null) { |
||
113 | return; |
||
114 | } |
||
115 | |||
116 | // check if parent is allowed |
||
117 | foreach ($node->getAllowedParents() as $className) { |
||
118 | if ($className === $parentName) { |
||
119 | return; |
||
120 | } |
||
126 |