You are here

public function Twig_Environment::addFunction in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/Environment.php \Twig_Environment::addFunction()

Registers a Function.

Parameters

string|Twig_SimpleFunction $name The function name or a Twig_SimpleFunction instance:

Twig_FunctionInterface|Twig_SimpleFunction $function A Twig_FunctionInterface instance or a Twig_SimpleFunction instance:

File

vendor/Twig/Environment.php, line 934

Class

Twig_Environment
Stores the Twig configuration.

Code

public function addFunction($name, $function = null) {
  if (!$name instanceof Twig_SimpleFunction && !($function instanceof Twig_SimpleFunction || $function instanceof Twig_FunctionInterface)) {
    throw new LogicException('A function must be an instance of Twig_FunctionInterface or Twig_SimpleFunction');
  }
  if ($name instanceof Twig_SimpleFunction) {
    $function = $name;
    $name = $function
      ->getName();
  }
  if ($this->extensionInitialized) {
    throw new LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $name));
  }
  $this->staging
    ->addFunction($name, $function);
}