Get a function by name.
Subclasses may override this method and load functions differently; so no list of functions is available.
string $name function name:
Twig_Function|false A Twig_Function instance or false if the function does not exists
public function getFunction($name) {
if (null === $this->functions) {
$this
->getFunctions();
}
if (isset($this->functions[$name])) {
return $this->functions[$name];
}
foreach ($this->functions as $pattern => $function) {
$pattern = str_replace('\\*', '(.*?)', preg_quote($pattern, '#'), $count);
if ($count) {
if (preg_match('#^' . $pattern . '$#', $name, $matches)) {
array_shift($matches);
$function
->setArguments($matches);
return $function;
}
}
}
foreach ($this->functionCallbacks as $callback) {
if (false !== ($function = call_user_func($callback, $name))) {
return $function;
}
}
return false;
}