You are here

public function Twig_Environment::addTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/Environment.php \Twig_Environment::addTest()

Registers a Test.

Parameters

string|Twig_SimpleTest $name The test name or a Twig_SimpleTest instance:

Twig_TestInterface|Twig_SimpleTest $test A Twig_TestInterface instance or a Twig_SimpleTest instance:

File

vendor/twig/twig/lib/Twig/Environment.php, line 1012

Class

Twig_Environment
Stores the Twig configuration.

Code

public function addTest($name, $test = null) {
  if (!$name instanceof Twig_SimpleTest && !($test instanceof Twig_SimpleTest || $test instanceof Twig_TestInterface)) {
    throw new LogicException('A test must be an instance of Twig_TestInterface or Twig_SimpleTest');
  }
  if ($name instanceof Twig_SimpleTest) {
    $test = $name;
    $name = $test
      ->getName();
  }
  else {
    @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated. Pass an instance of "Twig_SimpleTest" instead when defining test "%s".', __METHOD__, $name), E_USER_DEPRECATED);
  }
  if ($this->extensionInitialized) {
    throw new LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $name));
  }
  $this->staging
    ->addTest($name, $test);
}