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

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

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();
  }
  if ($this->extensionInitialized) {
    throw new LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $name));
  }
  $this->staging
    ->addTest($name, $test);
}