ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Node_Expression_Test_Defined Class Reference

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

+ Inheritance diagram for Twig_Node_Expression_Test_Defined:
+ Collaboration diagram for Twig_Node_Expression_Test_Defined:

Public Member Functions

 __construct (Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments=null, $lineno)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
- Public Member Functions inherited from Twig_Node_Expression_Test
 __construct (Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments=null, $lineno)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
- Public Member Functions inherited from Twig_Node
 __construct (array $nodes=array(), array $attributes=array(), $lineno=0, $tag=null)
 Constructor. More...
 
 __toString ()
 
 toXml ($asDom=false)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
 getTemplateLine ()
 
 getLine ()
 
 getNodeTag ()
 
 hasAttribute ($name)
 
 getAttribute ($name)
 
 setAttribute ($name, $value)
 
 removeAttribute ($name)
 
 hasNode ($name)
 
 getNode ($name)
 
 setNode ($name, $node=null)
 
 removeNode ($name)
 
 count ()
 
 getIterator ()
 
 setTemplateName ($name)
 
 getTemplateName ()
 
 setFilename ($name)
 
 getFilename ()
 

Protected Member Functions

 changeIgnoreStrictCheck (Twig_Node_Expression_GetAttr $node)
 
- Protected Member Functions inherited from Twig_Node_Expression_Call
 compileCallable (Twig_Compiler $compiler)
 
 compileArguments (Twig_Compiler $compiler)
 
 getArguments ($callable, $arguments)
 
 normalizeName ($name)
 

Additional Inherited Members

- Protected Attributes inherited from Twig_Node
 $nodes
 
 $attributes
 
 $lineno
 
 $tag
 

Detailed Description

Checks if a variable is defined in the current context.

{# defined works with variable names and variable attributes #}
{% if foo is defined %}
    {# ... #}
{% endif %}
Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Definition at line 24 of file Defined.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Node_Expression_Test_Defined::__construct ( Twig_NodeInterface  $node,
  $name,
Twig_NodeInterface  $arguments = null,
  $lineno 
)

Definition at line 26 of file Defined.php.

References Twig_Node\$lineno, Twig_Node\$name, changeIgnoreStrictCheck(), and Twig_Node\getTemplateLine().

27  {
28  if ($node instanceof Twig_Node_Expression_Name) {
29  $node->setAttribute('is_defined_test', true);
30  } elseif ($node instanceof Twig_Node_Expression_GetAttr) {
31  $node->setAttribute('is_defined_test', true);
32  $this->changeIgnoreStrictCheck($node);
33  } elseif ($node instanceof Twig_Node_Expression_BlockReference) {
34  $node->setAttribute('is_defined_test', true);
35  } elseif ($node instanceof Twig_Node_Expression_Function && 'constant' === $node->getAttribute('name')) {
36  $node->setAttribute('is_defined_test', true);
37  } elseif ($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array) {
38  $node = new Twig_Node_Expression_Constant(true, $node->getTemplateLine());
39  } else {
40  throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getTemplateLine());
41  }
42 
43  parent::__construct($node, $name, $arguments, $lineno);
44  }
$lineno
Definition: Node.php:22
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node)
Definition: Defined.php:46
getTemplateLine()
Definition: Node.php:121
Represents a block call node.
+ Here is the call graph for this function:

Member Function Documentation

◆ changeIgnoreStrictCheck()

Twig_Node_Expression_Test_Defined::changeIgnoreStrictCheck ( Twig_Node_Expression_GetAttr  $node)
protected

Definition at line 46 of file Defined.php.

References Twig_Node\getNode(), and Twig_Node\setAttribute().

Referenced by __construct().

47  {
48  $node->setAttribute('ignore_strict_check', true);
49 
50  if ($node->getNode('node') instanceof Twig_Node_Expression_GetAttr) {
51  $this->changeIgnoreStrictCheck($node->getNode('node'));
52  }
53  }
changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node)
Definition: Defined.php:46
getNode($name)
Definition: Node.php:186
setAttribute($name, $value)
Definition: Node.php:165
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compile()

Twig_Node_Expression_Test_Defined::compile ( Twig_Compiler  $compiler)

Compiles the node to PHP.

Implements Twig_NodeInterface.

Definition at line 55 of file Defined.php.

References Twig_Node\getNode(), and Twig_Compiler\subcompile().

56  {
57  $compiler->subcompile($this->getNode('node'));
58  }
subcompile(Twig_NodeInterface $node, $raw=true)
Definition: Compiler.php:94
getNode($name)
Definition: Node.php:186
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: