Compare commits
5 Commits
8fb0a70311
...
065ccaec23
Author | SHA1 | Date |
---|---|---|
Ivan Shalganov | 065ccaec23 | |
Ivan Shalganov | 6650668b72 | |
Anton | b24d9d9e1e | |
Anton | 5e14c6bf90 | |
Anton | 79283c6f7f |
|
@ -27,7 +27,7 @@ $fenom->addFunction("some_function", $some_function, function (Fenom\Tokenizer $
|
||||||
Существует более простой способ добавления произвольной функции:
|
Существует более простой способ добавления произвольной функции:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$fenom->addFunctionSmarty(string $function_name, callable $callback);
|
$fenom->addFunctionSmart(string $function_name, callable $callback);
|
||||||
```
|
```
|
||||||
|
|
||||||
В данном случае парсер сканирует список аргументов коллбека и попробует сопоставить с аргументами тега.
|
В данном случае парсер сканирует список аргументов коллбека и попробует сопоставить с аргументами тега.
|
||||||
|
|
|
@ -200,6 +200,11 @@ class Fenom
|
||||||
"implode" => 1
|
"implode" => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string[] the disabled functions by `disable_functions` PHP's option
|
||||||
|
*/
|
||||||
|
protected $_disabled_funcs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array[] of compilers and functions
|
* @var array[] of compilers and functions
|
||||||
*/
|
*/
|
||||||
|
@ -769,16 +774,38 @@ class Fenom
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $function
|
* Checks if is allowed PHP function for using in templates.
|
||||||
|
*
|
||||||
|
* @param string $function the function name
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isAllowedFunction($function)
|
public function isAllowedFunction($function)
|
||||||
{
|
{
|
||||||
if ($this->_options & self::DENY_NATIVE_FUNCS) {
|
$function = (string) $function;
|
||||||
return isset($this->_allowed_funcs[$function]);
|
$allow = ($this->_options & self::DENY_NATIVE_FUNCS)
|
||||||
} else {
|
? isset($this->_allowed_funcs[$function])
|
||||||
return is_callable($function);
|
: function_exists($function);
|
||||||
|
return $allow && !in_array($function, $this->getDisabledFuncs(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the disabled PHP functions.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
protected function _getDisabledFuncs()
|
||||||
|
{
|
||||||
|
if (!is_array($this->_disabled_funcs)) {
|
||||||
|
$disabled = ini_get('disable_functions');
|
||||||
|
// adds execution functions to disabled for security
|
||||||
|
$this->_disabled_funcs = array_merge(
|
||||||
|
empty($disabled) ? [] : explode(',', $disabled),
|
||||||
|
array('exec', 'system', 'passthru', 'shell_exec', 'pcntl_exec', 'proc_open', 'popen'),
|
||||||
|
array('call_user_func', 'call_user_func_array')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->_disabled_funcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue