1cdc0dd07d0a838bcd9705ca12d53d17e81c3aa9
[yaffs-website] / vendor / twig / twig / lib / Twig / TokenParser / Filter.php
1 <?php
2
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  * Filters a section of a template by applying filters.
14  *
15  * <pre>
16  * {% filter upper %}
17  *  This text becomes uppercase
18  * {% endfilter %}
19  * </pre>
20  *
21  * @final
22  */
23 class Twig_TokenParser_Filter extends Twig_TokenParser
24 {
25     public function parse(Twig_Token $token)
26     {
27         $name = $this->parser->getVarName();
28         $ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), null, $token->getLine(), $this->getTag());
29
30         $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
31         $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
32
33         $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
34         $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
35
36         $block = new Twig_Node_Block($name, $body, $token->getLine());
37         $this->parser->setBlock($name, $block);
38
39         return new Twig_Node_Print($filter, $token->getLine(), $this->getTag());
40     }
41
42     public function decideBlockEnd(Twig_Token $token)
43     {
44         return $token->test('endfilter');
45     }
46
47     public function getTag()
48     {
49         return 'filter';
50     }
51 }