public function 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

drupal/core/vendor/twig/twig/lib/Twig/Environment.php, line 932

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;
}