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@symfony.com>
|
17
|
*/
|
18
|
abstract class Twig_Function implements Twig_FunctionInterface
|
19
|
{
|
20
|
protected $options;
|
21
|
protected $arguments = array();
|
22
|
|
23
|
public function __construct(array $options = array())
|
24
|
{
|
25
|
$this->options = array_merge(array(
|
26
|
'needs_environment' => false,
|
27
|
'needs_context' => false,
|
28
|
), $options);
|
29
|
}
|
30
|
|
31
|
public function setArguments($arguments)
|
32
|
{
|
33
|
$this->arguments = $arguments;
|
34
|
}
|
35
|
|
36
|
public function getArguments()
|
37
|
{
|
38
|
return $this->arguments;
|
39
|
}
|
40
|
|
41
|
public function needsEnvironment()
|
42
|
{
|
43
|
return $this->options['needs_environment'];
|
44
|
}
|
45
|
|
46
|
public function needsContext()
|
47
|
{
|
48
|
return $this->options['needs_context'];
|
49
|
}
|
50
|
|
51
|
public function getSafe(Twig_Node $functionArgs)
|
52
|
{
|
53
|
if (isset($this->options['is_safe'])) {
|
54
|
return $this->options['is_safe'];
|
55
|
}
|
56
|
|
57
|
if (isset($this->options['is_safe_callback'])) {
|
58
|
return call_user_func($this->options['is_safe_callback'], $functionArgs);
|
59
|
}
|
60
|
|
61
|
return array();
|
62
|
}
|
63
|
}
|