PhpFunctionExtension.php
1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Umpirsky\Twig\Extension;
use Twig_Extension;
use Twig_SimpleFunction;
use BadFunctionCallException;
class PhpFunctionExtension extends Twig_Extension
{
private $functions = array(
'uniqid',
'floor',
'ceil',
'addslashes',
'chr',
'chunk_split',
'convert_uudecode',
'crc32',
'crypt',
'hex2bin',
'md5',
'sha1',
'strpos',
'strrpos',
'ucwords',
'wordwrap',
'gettype',
);
public function __construct(array $functions = array())
{
if ($functions) {
$this->allowFunctions($functions);
}
}
public function getFunctions()
{
$twigFunctions = array();
foreach ($this->functions as $function) {
$twigFunctions[] = new Twig_SimpleFunction($function, $function);
}
return $twigFunctions;
}
public function allowFunction($function)
{
$this->functions[] = $function;
}
public function allowFunctions(array $functions)
{
$this->functions = $functions;
}
public function getName()
{
return 'php_function';
}
}