You are here

public function Twig_Environment::addFunction in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/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/twig/lib/Twig/Environment.php, line 1072

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();
  }
  else {
    @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated. Pass an instance of "Twig_SimpleFunction" instead when defining function "%s".', __METHOD__, $name), E_USER_DEPRECATED);
  }
  if ($this->extensionInitialized) {
    throw new LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $name));
  }
  $this->staging
    ->addFunction($name, $function);
}