Completed
Pull Request — master (#61)
by Vladimir
09:45
created

TokenParser::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace allejo\stakx\Templating\Twig\MarkupBlock;
4
5
use Twig_Token;
6
7
/**
8
 * @author Gunnar Lium <[email protected]>
9
 * @author Joris Berthelot <[email protected]>
10
 *
11
 * @link https://github.com/aptoma/twig-markdown/blob/master/src/Aptoma/Twig/TokenParser/MarkdownTokenParser.php
12
 */
13
class TokenParser extends \Twig_TokenParser
14
{
15
    private $tagName;
16
17
    public function __construct($tagName)
18
    {
19
        $this->tagName = $tagName;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function parse(Twig_Token $token)
26
    {
27
        $lineNumber = $token->getLine();
28
29
        $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
30
        $body = $this->parser->subparse([$this, 'decideEndTag'], true);
31
        $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
32
33
        return new Node($body, $lineNumber, $this->getTag());
34
    }
35
36
    /**
37
     * Decide if current token marks end of our markup block.
38
     *
39
     * @param Twig_Token $token
40
     *
41
     * @return bool
42
     */
43
    public function decideEndTag(\Twig_Token $token)
44
    {
45
        return $token->test('end' . $this->getTag());
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getTag()
52
    {
53
        return $this->tagName;
54
    }
55
}
56