From 874b8cbf002e9d8bf0ff39671e1501165016320a Mon Sep 17 00:00:00 2001 From: Michael Save Date: Mon, 9 Apr 2012 20:52:26 +1000 Subject: inc/contrib -> inc/lib --- inc/lib/Twig/Function.php | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 inc/lib/Twig/Function.php (limited to 'inc/lib/Twig/Function.php') diff --git a/inc/lib/Twig/Function.php b/inc/lib/Twig/Function.php new file mode 100644 index 00000000..1197924a --- /dev/null +++ b/inc/lib/Twig/Function.php @@ -0,0 +1,52 @@ + + */ +abstract class Twig_Function implements Twig_FunctionInterface +{ + protected $options; + + public function __construct(array $options = array()) + { + $this->options = array_merge(array( + 'needs_environment' => false, + 'needs_context' => false, + ), $options); + } + + public function needsEnvironment() + { + return $this->options['needs_environment']; + } + + public function needsContext() + { + return $this->options['needs_context']; + } + + public function getSafe(Twig_Node $functionArgs) + { + if (isset($this->options['is_safe'])) { + return $this->options['is_safe']; + } + + if (isset($this->options['is_safe_callback'])) { + return call_user_func($this->options['is_safe_callback'], $functionArgs); + } + + return array(); + } +} -- cgit v1.3