1 | <?php |
||
2 | |||
3 | namespace Frontend\Core\Engine; |
||
4 | |||
5 | /** |
||
6 | * Twig token parser for form closing tag. |
||
7 | */ |
||
8 | class FormEndTokenParser extends \Twig_TokenParser |
||
9 | { |
||
10 | /** |
||
11 | * @param \Twig_Token $token Token consumed by the lexer. |
||
12 | * |
||
13 | * @throws \Twig_Error_Syntax |
||
14 | * |
||
15 | * @return \Twig_Node |
||
16 | */ |
||
17 | public function parse(\Twig_Token $token): \Twig_Node |
||
18 | { |
||
19 | $stream = $this->parser->getStream(); |
||
20 | if ($stream->getCurrent()->getType() !== \Twig_Token::BLOCK_END_TYPE) { |
||
21 | $error = sprintf("'%s' does not require any arguments.", $this->getTag()); |
||
22 | throw new \Twig_Error_Syntax( |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||
23 | $error, |
||
24 | $token->getLine(), |
||
25 | $this->parser->getStream()->getSourceContext()->getPath() |
||
26 | ); |
||
27 | } |
||
28 | $stream->expect(\Twig_Token::BLOCK_END_TYPE); |
||
29 | |||
30 | if (FormState::$current === null) { |
||
31 | throw new \Twig_Error_Syntax( |
||
32 | 'Trying to close a form tag, while none opened', |
||
33 | $token->getLine(), |
||
34 | $this->parser->getStream()->getSourceContext()->getPath() |
||
35 | ); |
||
36 | } |
||
37 | |||
38 | FormState::$current = null; |
||
39 | |||
40 | return new FormEndNode($token->getLine(), $this->getTag()); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return string |
||
45 | */ |
||
46 | public function getTag(): string |
||
47 | { |
||
48 | return 'endform'; |
||
49 | } |
||
50 | } |
||
51 |