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