1 | <?php |
||
11 | class SyntaxCheckNodeVisitor extends \Twig_BaseNodeVisitor |
||
12 | { |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $path = []; |
||
17 | |||
18 | /** |
||
19 | * {@inheritdoc} |
||
20 | */ |
||
21 | public function getPriority() |
||
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | * |
||
29 | * @throws \Twig_Error_Syntax |
||
30 | */ |
||
31 | protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env) |
||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | protected function doLeaveNode(\Twig_Node $node, \ Twig_Environment $env) |
||
59 | |||
60 | /** |
||
61 | * @param \Twig_Node $node |
||
62 | * |
||
63 | * @throws \Twig_Error_Syntax |
||
64 | */ |
||
65 | private function checkAllowedChildren(\Twig_Node $node) |
||
66 | { |
||
67 | $hasDocumentNode = false; |
||
68 | $hasTextNode = false; |
||
69 | |||
70 | /** |
||
71 | * @var \Twig_Node $currentNode |
||
72 | */ |
||
73 | foreach ($node->getIterator() as $currentNode) { |
||
74 | if ($currentNode instanceof \Twig_Node_Text) { |
||
75 | if ($hasDocumentNode) { |
||
76 | throw new \Twig_Error_Syntax(sprintf('Node "%s" is not allowed after Node "%s".', \Twig_Node_Text::class, DocumentNode::class)); |
||
77 | } |
||
78 | $hasTextNode = true; |
||
79 | } elseif ($currentNode instanceof DocumentNode) { |
||
80 | if ($hasTextNode) { |
||
81 | throw new \Twig_Error_Syntax(sprintf('Node "%s" is not allowed before Node "%s".', \Twig_Node_Text::class, DocumentNode::class)); |
||
82 | } |
||
83 | $hasDocumentNode = true; |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @param BaseNode $node |
||
90 | * |
||
91 | * @throws \Twig_Error_Syntax |
||
92 | */ |
||
93 | private function checkAllowedParents(BaseNode $node) |
||
119 | } |
||
120 |