You are here

class Twig_Node_Expression_Test_Defined in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/twig/twig/lib/Twig/Node/Expression/Test/Defined.php \Twig_Node_Expression_Test_Defined

Checks if a variable is defined in the current context.

<pre> {# defined works with variable names and variable attributes #} {% if foo is defined %} {# ... #} {% endif %} </pre>

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of Twig_Node_Expression_Test_Defined

1 string reference to 'Twig_Node_Expression_Test_Defined'
Twig_Extension_Core::getTests in vendor/twig/twig/lib/Twig/Extension/Core.php

File

vendor/twig/twig/lib/Twig/Node/Expression/Test/Defined.php, line 24

View source
class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test {
  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());
    }
  }
  protected function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node) {
    $node
      ->setAttribute('ignore_strict_check', true);
    if ($node
      ->getNode('node') instanceof Twig_Node_Expression_GetAttr) {
      $this
        ->changeIgnoreStrictCheck($node
        ->getNode('node'));
    }
  }
  public function compile(Twig_Compiler $compiler) {
    $compiler
      ->subcompile($this
      ->getNode('node'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Twig_Node::$attributes protected property
Twig_Node::$lineno protected property
Twig_Node::$nodes protected property
Twig_Node::$tag protected property
Twig_Node::count public function
Twig_Node::getAttribute public function Gets an attribute value by name.
Twig_Node::getIterator public function
Twig_Node::getLine public function Overrides Twig_NodeInterface::getLine
Twig_Node::getNode public function Gets a node by name.
Twig_Node::getNodeTag public function Overrides Twig_NodeInterface::getNodeTag
Twig_Node::hasAttribute public function Returns true if the attribute is defined.
Twig_Node::hasNode public function Returns true if the node with the given name exists.
Twig_Node::removeAttribute public function Removes an attribute by name.
Twig_Node::removeNode public function Removes a node by name.
Twig_Node::setAttribute public function Sets an attribute by name to a value.
Twig_Node::setNode public function Sets a node.
Twig_Node::toXml Deprecated public function
Twig_Node::__toString public function
Twig_Node_Expression_Call::compileArguments protected function
Twig_Node_Expression_Call::compileCallable protected function
Twig_Node_Expression_Call::getArguments protected function 1
Twig_Node_Expression_Call::normalizeName protected function
Twig_Node_Expression_Test_Defined::changeIgnoreStrictCheck protected function
Twig_Node_Expression_Test_Defined::compile public function Compiles the node to PHP. Overrides Twig_Node_Expression_Test::compile
Twig_Node_Expression_Test_Defined::__construct public function Constructor. Overrides Twig_Node_Expression_Test::__construct