public function Twig_Environment::getFunction in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/twig/twig/lib/Twig/Environment.php \Twig_Environment::getFunction()
Get a function by name.
Subclasses may override this method and load functions differently; so no list of functions is available.
Parameters
string $name function name:
Return value
Twig_Function|false A Twig_Function instance or false if the function does not exist
File
- vendor/
twig/ twig/ lib/ Twig/ Environment.php, line 1102
Class
- Twig_Environment
- Stores the Twig configuration.
Code
public function getFunction($name) {
if (!$this->extensionInitialized) {
$this
->initExtensions();
}
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;
}