| [991] | 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 | * |
|---|
| [1101] | 15 | * Use Twig_SimpleFunction instead. |
|---|
| 16 | * |
|---|
| [991] | 17 | * @package twig |
|---|
| 18 | * @author Fabien Potencier <fabien@symfony.com> |
|---|
| [1101] | 19 | * @deprecated since 1.12 (to be removed in 2.0) |
|---|
| [991] | 20 | */ |
|---|
| [1101] | 21 | abstract class Twig_Function implements Twig_FunctionInterface, Twig_FunctionCallableInterface |
|---|
| [991] | 22 | { |
|---|
| 23 | protected $options; |
|---|
| 24 | protected $arguments = array(); |
|---|
| 25 | |
|---|
| 26 | public function __construct(array $options = array()) |
|---|
| 27 | { |
|---|
| 28 | $this->options = array_merge(array( |
|---|
| 29 | 'needs_environment' => false, |
|---|
| 30 | 'needs_context' => false, |
|---|
| [1101] | 31 | 'callable' => null, |
|---|
| [991] | 32 | ), $options); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | public function setArguments($arguments) |
|---|
| 36 | { |
|---|
| 37 | $this->arguments = $arguments; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | public function getArguments() |
|---|
| 41 | { |
|---|
| 42 | return $this->arguments; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | public function needsEnvironment() |
|---|
| 46 | { |
|---|
| 47 | return $this->options['needs_environment']; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | public function needsContext() |
|---|
| 51 | { |
|---|
| 52 | return $this->options['needs_context']; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | public function getSafe(Twig_Node $functionArgs) |
|---|
| 56 | { |
|---|
| 57 | if (isset($this->options['is_safe'])) { |
|---|
| 58 | return $this->options['is_safe']; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | if (isset($this->options['is_safe_callback'])) { |
|---|
| 62 | return call_user_func($this->options['is_safe_callback'], $functionArgs); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | return array(); |
|---|
| 66 | } |
|---|
| [1101] | 67 | |
|---|
| 68 | public function getCallable() |
|---|
| 69 | { |
|---|
| 70 | return $this->options['callable']; |
|---|
| 71 | } |
|---|
| [991] | 72 | } |
|---|