You are here

public function Twig_Node_Expression_Test_Defined::__construct in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/Node/Expression/Test/Defined.php \Twig_Node_Expression_Test_Defined::__construct()

Constructor.

The nodes are automatically made available as properties ($this->node). The attributes are automatically made available as array items ($this['name']).

Parameters

array $nodes An array of named nodes:

array $attributes An array of attributes (should not be nodes):

int $lineno The line number:

string $tag The tag name associated with the Node:

Overrides Twig_Node_Expression_Test::__construct

File

vendor/Twig/Node/Expression/Test/Defined.php, line 26

Class

Twig_Node_Expression_Test_Defined
Checks if a variable is defined in the current context.

Code

public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno) {
  parent::__construct($node, $name, $arguments, $lineno);
  if ($node instanceof Twig_Node_Expression_Name) {
    $node
      ->setAttribute('is_defined_test', true);
  }
  elseif ($node instanceof Twig_Node_Expression_GetAttr) {
    $node
      ->setAttribute('is_defined_test', true);
    $this
      ->changeIgnoreStrictCheck($node);
  }
  else {
    throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this
      ->getLine());
  }
}