Completed
Push — master ( c8fd93...a9ab00 )
by Georges
01:49
created

Cache::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
/**
4
 *
5
 * This file is part of phpFastCache.
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For full copyright and license information, please see the docs/CREDITS.txt file.
10
 *
11
 * @author Georges.L (Geolim4)  <[email protected]>
12
 * @author PastisD https://github.com/PastisD
13
 * @author Alexander (asm89) <[email protected]>
14
 * @author Khoa Bui (khoaofgod)  <[email protected]> http://www.phpfastcache.com
15
 *
16
 */
17
18
namespace phpFastCache\Bundle\Twig\CacheExtension\TokenParser;
19
20
use phpFastCache\Bundle\Twig\CacheExtension\Node\CacheNode;
21
22
/**
23
 * Parser for cache/endcache blocks.
24
 *
25
 * @author Alexander <[email protected]>
26
 */
27
class Cache extends \Twig_TokenParser
28
{
29
    /**
30
     * @param \Twig_Token $token
31
     *
32
     * @return boolean
33
     */
34
    public function decideCacheEnd(\Twig_Token $token)
35
    {
36
        return $token->test('endcache');
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function getTag()
43
    {
44
        return 'cache';
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50
    public function parse(\Twig_Token $token)
51
    {
52
        $lineno = $token->getLine();
53
        $stream = $this->parser->getStream();
54
55
        $annotation = $this->parser->getExpressionParser()->parseExpression();
56
57
        $key = $this->parser->getExpressionParser()->parseExpression();
58
59
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
60
        $body = $this->parser->subparse(array($this, 'decideCacheEnd'), true);
61
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
62
63
        return new CacheNode($annotation, $key, $body, $lineno, $this->getTag());
64
    }
65
}
66