Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
defineparser
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 parse
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
3
 decideBlockEnd
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTag
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @copyright Portions (c) 2009 Fabien Potencier, Armin Ronacher
8* @license GNU General Public License, version 2 (GPL-2.0)
9*
10* For full copyright and license information, please see
11* the docs/CREDITS.txt file.
12*
13*/
14
15namespace phpbb\template\twig\tokenparser;
16
17class defineparser extends \Twig\TokenParser\AbstractTokenParser
18{
19    /**
20    * Parses a token and returns a node.
21    *
22    * @param \Twig\Token $token A Twig\Token instance
23    *
24    * @throws \Twig\Error\SyntaxError
25    * @return \Twig\Node\Node A Twig\Node instance
26    */
27    public function parse(\Twig\Token $token)
28    {
29        $lineno = $token->getLine();
30        $stream = $this->parser->getStream();
31        $name = $this->parser->getExpressionParser()->parseExpression();
32
33        $capture = false;
34        if ($stream->test(\Twig\Token::OPERATOR_TYPE, '='))
35        {
36            $stream->next();
37            $value = $this->parser->getExpressionParser()->parseExpression();
38
39            if ($value instanceof \Twig\Node\Expression\NameExpression)
40            {
41                // This would happen if someone improperly formed their DEFINE syntax
42                // e.g. <!-- DEFINE $VAR = foo -->
43                throw new \Twig\Error\SyntaxError('Invalid DEFINE', $token->getLine(), $this->parser->getStream()->getSourceContext());
44            }
45
46            $stream->expect(\Twig\Token::BLOCK_END_TYPE);
47        }
48        else
49        {
50            $capture = true;
51
52            $stream->expect(\Twig\Token::BLOCK_END_TYPE);
53
54            $value = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
55            $stream->expect(\Twig\Token::BLOCK_END_TYPE);
56        }
57
58        return new \phpbb\template\twig\node\definenode($capture, $name, $value, $lineno, $this->getTag());
59    }
60
61    public function decideBlockEnd(\Twig\Token $token)
62    {
63        return $token->test('ENDDEFINE');
64    }
65
66    /**
67    * Gets the tag name associated with this token parser.
68    *
69    * @return string The tag name
70    */
71    public function getTag()
72    {
73        return 'DEFINE';
74    }
75}