ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Twig_Node_Expression_Name Class Reference
+ Inheritance diagram for Twig_Node_Expression_Name:
+ Collaboration diagram for Twig_Node_Expression_Name:

Public Member Functions

 __construct ($name, $lineno)
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
 isSpecial ()
 
 isSimple ()
 
- 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 Attributes

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

Detailed Description

Definition at line 12 of file Name.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Node_Expression_Name::__construct (   $name,
  $lineno 
)

Definition at line 20 of file Name.php.

References Twig_Node\$lineno, and Twig_Node\$name.

21  {
22  parent::__construct(array(), array('name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false), $lineno);
23  }
$lineno
Definition: Node.php:22

Member Function Documentation

◆ compile()

Twig_Node_Expression_Name::compile ( Twig_Compiler  $compiler)

Compiles the node to PHP.

Implements Twig_NodeInterface.

Definition at line 25 of file Name.php.

References Twig_Node\$name, Twig_Compiler\addDebugInfo(), Twig_Node\getAttribute(), Twig_Compiler\getEnvironment(), isSpecial(), Twig_Compiler\raw(), and Twig_Compiler\repr().

26  {
27  $name = $this->getAttribute('name');
28 
29  $compiler->addDebugInfo($this);
30 
31  if ($this->getAttribute('is_defined_test')) {
32  if ($this->isSpecial()) {
33  $compiler->repr(true);
34  } else {
35  $compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
36  }
37  } elseif ($this->isSpecial()) {
38  $compiler->raw($this->specialVars[$name]);
39  } elseif ($this->getAttribute('always_defined')) {
40  $compiler
41  ->raw('$context[')
42  ->string($name)
43  ->raw(']')
44  ;
45  } else {
46  if (PHP_VERSION_ID >= 70000) {
47  // use PHP 7 null coalescing operator
48  $compiler
49  ->raw('($context[')
50  ->string($name)
51  ->raw('] ?? ')
52  ;
53 
54  if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
55  $compiler->raw('null)');
56  } else {
57  $compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
58  }
59  } elseif (PHP_VERSION_ID >= 50400) {
60  // PHP 5.4 ternary operator performance was optimized
61  $compiler
62  ->raw('(isset($context[')
63  ->string($name)
64  ->raw(']) ? $context[')
65  ->string($name)
66  ->raw('] : ')
67  ;
68 
69  if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
70  $compiler->raw('null)');
71  } else {
72  $compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
73  }
74  } else {
75  $compiler
76  ->raw('$this->getContext($context, ')
77  ->string($name)
78  ;
79 
80  if ($this->getAttribute('ignore_strict_check')) {
81  $compiler->raw(', true');
82  }
83 
84  $compiler
85  ->raw(')')
86  ;
87  }
88  }
89  }
raw($string)
Adds a raw string to the compiled code.
Definition: Compiler.php:112
repr($value)
Returns a PHP representation of a given value.
Definition: Compiler.php:171
getAttribute($name)
Definition: Node.php:152
getEnvironment()
Returns the environment instance related to this compiler.
Definition: Compiler.php:50
addDebugInfo(Twig_NodeInterface $node)
Adds debugging information.
Definition: Compiler.php:212
+ Here is the call graph for this function:

◆ isSimple()

Twig_Node_Expression_Name::isSimple ( )

Definition at line 96 of file Name.php.

References Twig_Node\getAttribute(), and isSpecial().

97  {
98  return !$this->isSpecial() && !$this->getAttribute('is_defined_test');
99  }
getAttribute($name)
Definition: Node.php:152
+ Here is the call graph for this function:

◆ isSpecial()

Twig_Node_Expression_Name::isSpecial ( )

Definition at line 91 of file Name.php.

References Twig_Node\getAttribute().

Referenced by compile(), and isSimple().

92  {
93  return isset($this->specialVars[$this->getAttribute('name')]);
94  }
getAttribute($name)
Definition: Node.php:152
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $specialVars

Twig_Node_Expression_Name::$specialVars
protected
Initial value:
= array(
'_self' => '$this',
'_context' => '$context',
'_charset' => '$this->env->getCharset()',
)

Definition at line 14 of file Name.php.


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