1
|
<?php
|
2
|
|
3
|
/*
|
4
|
* This file is part of Twig.
|
5
|
*
|
6
|
* (c) 2009 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
|
class Twig_TokenParser_Filter extends Twig_TokenParser
|
22
|
{
|
23
|
public function parse(Twig_Token $token)
|
24
|
{
|
25
|
$name = $this->parser->getVarName();
|
26
|
$ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), true, $token->getLine(), $this->getTag());
|
27
|
|
28
|
$filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
|
29
|
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
30
|
|
31
|
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
|
32
|
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
33
|
|
34
|
$block = new Twig_Node_Block($name, $body, $token->getLine());
|
35
|
$this->parser->setBlock($name, $block);
|
36
|
|
37
|
return new Twig_Node_Print($filter, $token->getLine(), $this->getTag());
|
38
|
}
|
39
|
|
40
|
public function decideBlockEnd(Twig_Token $token)
|
41
|
{
|
42
|
return $token->test('endfilter');
|
43
|
}
|
44
|
|
45
|
public function getTag()
|
46
|
{
|
47
|
return 'filter';
|
48
|
}
|
49
|
}
|