Line | |
---|
1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | * This file is part of Twig. |
---|
5 | * |
---|
6 | * (c) 2010 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 function. |
---|
14 | * |
---|
15 | * @package twig |
---|
16 | * @author Fabien Potencier <fabien.potencier@symfony-project.com> |
---|
17 | */ |
---|
18 | abstract class Twig_Function implements Twig_FunctionInterface |
---|
19 | { |
---|
20 | protected $options; |
---|
21 | |
---|
22 | public function __construct(array $options = array()) |
---|
23 | { |
---|
24 | $this->options = array_merge(array( |
---|
25 | 'needs_environment' => false, |
---|
26 | 'needs_context' => false, |
---|
27 | ), $options); |
---|
28 | } |
---|
29 | |
---|
30 | public function needsEnvironment() |
---|
31 | { |
---|
32 | return $this->options['needs_environment']; |
---|
33 | } |
---|
34 | |
---|
35 | public function needsContext() |
---|
36 | { |
---|
37 | return $this->options['needs_context']; |
---|
38 | } |
---|
39 | |
---|
40 | public function getSafe(Twig_Node $functionArgs) |
---|
41 | { |
---|
42 | if (isset($this->options['is_safe'])) { |
---|
43 | return $this->options['is_safe']; |
---|
44 | } |
---|
45 | |
---|
46 | if (isset($this->options['is_safe_callback'])) { |
---|
47 | return call_user_func($this->options['is_safe_callback'], $functionArgs); |
---|
48 | } |
---|
49 | |
---|
50 | return array(); |
---|
51 | } |
---|
52 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.