4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
13 * Represents a template function.
17 * @author Fabien Potencier <fabien@symfony.com>
19 class Twig_SimpleFunction
24 protected $arguments = array();
26 public function __construct($name, $callable, array $options = array())
29 $this->callable = $callable;
30 $this->options = array_merge(array(
31 'needs_environment' => false,
32 'needs_context' => false,
33 'is_variadic' => false,
35 'is_safe_callback' => null,
36 'node_class' => 'Twig_Node_Expression_Function',
37 'deprecated' => false,
38 'alternative' => null,
42 public function getName()
47 public function getCallable()
49 return $this->callable;
52 public function getNodeClass()
54 return $this->options['node_class'];
57 public function setArguments($arguments)
59 $this->arguments = $arguments;
62 public function getArguments()
64 return $this->arguments;
67 public function needsEnvironment()
69 return $this->options['needs_environment'];
72 public function needsContext()
74 return $this->options['needs_context'];
77 public function getSafe(Twig_Node $functionArgs)
79 if (null !== $this->options['is_safe']) {
80 return $this->options['is_safe'];
83 if (null !== $this->options['is_safe_callback']) {
84 return call_user_func($this->options['is_safe_callback'], $functionArgs);
90 public function isVariadic()
92 return $this->options['is_variadic'];
95 public function isDeprecated()
97 return (bool) $this->options['deprecated'];
100 public function getDeprecatedVersion()
102 return $this->options['deprecated'];
105 public function getAlternative()
107 return $this->options['alternative'];
111 class_alias('Twig_SimpleFunction', 'Twig\TwigFunction', false);