Files
apps.prometeysev.ru/vendor/umpirsky/twig-php-function/src/Umpirsky/Twig/Extension/PhpFunctionExtension.php
T

64 lines
1.2 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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';
}
}