1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | * This file is part of Twig. |
---|
5 | * |
---|
6 | * (c) 2009-2012 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 | * Represents a template filter. |
---|
14 | * |
---|
15 | * @package twig |
---|
16 | * @author Fabien Potencier <fabien@symfony.com> |
---|
17 | */ |
---|
18 | class Twig_SimpleFilter |
---|
19 | { |
---|
20 | protected $name; |
---|
21 | protected $callable; |
---|
22 | protected $options; |
---|
23 | protected $arguments = array(); |
---|
24 | |
---|
25 | public function __construct($name, $callable, array $options = array()) |
---|
26 | { |
---|
27 | $this->name = $name; |
---|
28 | $this->callable = $callable; |
---|
29 | $this->options = array_merge(array( |
---|
30 | 'needs_environment' => false, |
---|
31 | 'needs_context' => false, |
---|
32 | 'is_safe' => null, |
---|
33 | 'is_safe_callback' => null, |
---|
34 | 'pre_escape' => null, |
---|
35 | 'preserves_safety' => null, |
---|
36 | 'node_class' => 'Twig_Node_Expression_Filter', |
---|
37 | ), $options); |
---|
38 | } |
---|
39 | |
---|
40 | public function getName() |
---|
41 | { |
---|
42 | return $this->name; |
---|
43 | } |
---|
44 | |
---|
45 | public function getCallable() |
---|
46 | { |
---|
47 | return $this->callable; |
---|
48 | } |
---|
49 | |
---|
50 | public function getNodeClass() |
---|
51 | { |
---|
52 | return $this->options['node_class']; |
---|
53 | } |
---|
54 | |
---|
55 | public function setArguments($arguments) |
---|
56 | { |
---|
57 | $this->arguments = $arguments; |
---|
58 | } |
---|
59 | |
---|
60 | public function getArguments() |
---|
61 | { |
---|
62 | return $this->arguments; |
---|
63 | } |
---|
64 | |
---|
65 | public function needsEnvironment() |
---|
66 | { |
---|
67 | return $this->options['needs_environment']; |
---|
68 | } |
---|
69 | |
---|
70 | public function needsContext() |
---|
71 | { |
---|
72 | return $this->options['needs_context']; |
---|
73 | } |
---|
74 | |
---|
75 | public function getSafe(Twig_Node $filterArgs) |
---|
76 | { |
---|
77 | if (null !== $this->options['is_safe']) { |
---|
78 | return $this->options['is_safe']; |
---|
79 | } |
---|
80 | |
---|
81 | if (null !== $this->options['is_safe_callback']) { |
---|
82 | return call_user_func($this->options['is_safe_callback'], $filterArgs); |
---|
83 | } |
---|
84 | |
---|
85 | return null; |
---|
86 | } |
---|
87 | |
---|
88 | public function getPreservesSafety() |
---|
89 | { |
---|
90 | return $this->options['preserves_safety']; |
---|
91 | } |
---|
92 | |
---|
93 | public function getPreEscape() |
---|
94 | { |
---|
95 | return $this->options['pre_escape']; |
---|
96 | } |
---|
97 | } |
---|