You are here

public function Twig_Environment::getFunction in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/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/Environment.php, line 962

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