comparison src/Kachkaev/JstmplBundle/Twig/JstmplTokenParser.php @ 0:493bcb69166c

added public content
author Daniel Wolff
date Tue, 09 Feb 2016 20:54:02 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:493bcb69166c
1 <?php
2
3 namespace Kachkaev\JstmplBundle\Twig;
4
5 class JstmplTokenParser extends \Twig_TokenParser
6 {
7 public function parse(\Twig_Token $token)
8 {
9 $lineno = $token->getLine();
10
11 $stream = $this->parser->getStream();
12
13 while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
14 if ($stream->test(\Twig_Token::NAME_TYPE, 'id')) {
15 // id='tmpl_id'
16 $stream->next();
17 $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
18 $id = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
19 } else {
20 $token = $stream->getCurrent();
21 throw new \Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', \Twig_Token::typeToEnglish($token->getType(), $token->getLine()), $token->getValue()), $token->getLine());
22 }
23 }
24
25 $stream->expect(\Twig_Token::BLOCK_END_TYPE);
26
27 $endtag = 'end'.$this->getTag();
28 $test = function(\Twig_Token $token) use($endtag) {
29 return $token->test($endtag);
30 };
31 $body = $this->parser->subparse($test, true);
32
33 $stream->expect(\Twig_Token::BLOCK_END_TYPE);
34
35 return new JstmplNode($id, $body, $lineno, $this->getTag());
36 }
37
38 public function getTag()
39 {
40 return 'jstmpl';
41 }
42 }