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

Public Member Functions

 __construct (array $elements, $lineno)
 
 getKeyValuePairs ()
 
 hasElement (Twig_Node_Expression $key)
 
 addElement (Twig_Node_Expression $value, Twig_Node_Expression $key=null)
 
 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 ()
 
 compile (Twig_Compiler $compiler)
 Compiles the node to PHP. More...
 
 getLine ()
 
 getNodeTag ()
 

Protected Attributes

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

Detailed Description

Definition at line 11 of file Array.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Node_Expression_Array::__construct ( array  $elements,
  $lineno 
)

Definition at line 15 of file Array.php.

16 {
17 parent::__construct($elements, array(), $lineno);
18
19 $this->index = -1;
20 foreach ($this->getKeyValuePairs() as $pair) {
21 if ($pair['key'] instanceof Twig_Node_Expression_Constant && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) {
22 $this->index = $pair['key']->getAttribute('value');
23 }
24 }
25 }
getAttribute($name)
Definition: Node.php:152
$lineno
Definition: Node.php:22

References Twig_Node\$lineno, Twig_Node\getAttribute(), and getKeyValuePairs().

+ Here is the call graph for this function:

Member Function Documentation

◆ addElement()

Twig_Node_Expression_Array::addElement ( Twig_Node_Expression  $value,
Twig_Node_Expression  $key = null 
)

Definition at line 54 of file Array.php.

55 {
56 if (null === $key) {
57 $key = new Twig_Node_Expression_Constant(++$this->index, $value->getTemplateLine());
58 }
59
60 array_push($this->nodes, $key, $value);
61 }
getTemplateLine()
Definition: Node.php:121
$key
Definition: croninfo.php:18

References $key, and Twig_Node\getTemplateLine().

+ Here is the call graph for this function:

◆ compile()

Twig_Node_Expression_Array::compile ( Twig_Compiler  $compiler)

Compiles the node to PHP.

Reimplemented from Twig_Node.

Definition at line 63 of file Array.php.

64 {
65 $compiler->raw('array(');
66 $first = true;
67 foreach ($this->getKeyValuePairs() as $pair) {
68 if (!$first) {
69 $compiler->raw(', ');
70 }
71 $first = false;
72
73 $compiler
74 ->subcompile($pair['key'])
75 ->raw(' => ')
76 ->subcompile($pair['value'])
77 ;
78 }
79 $compiler->raw(')');
80 }
raw($string)
Adds a raw string to the compiled code.
Definition: Compiler.php:112
subcompile(Twig_NodeInterface $node, $raw=true)
Definition: Compiler.php:94

References getKeyValuePairs(), Twig_Compiler\raw(), and Twig_Compiler\subcompile().

+ Here is the call graph for this function:

◆ getKeyValuePairs()

Twig_Node_Expression_Array::getKeyValuePairs ( )

Definition at line 27 of file Array.php.

28 {
29 $pairs = array();
30
31 foreach (array_chunk($this->nodes, 2) as $pair) {
32 $pairs[] = array(
33 'key' => $pair[0],
34 'value' => $pair[1],
35 );
36 }
37
38 return $pairs;
39 }

Referenced by __construct(), compile(), and hasElement().

+ Here is the caller graph for this function:

◆ hasElement()

Twig_Node_Expression_Array::hasElement ( Twig_Node_Expression  $key)

Definition at line 41 of file Array.php.

42 {
43 foreach ($this->getKeyValuePairs() as $pair) {
44 // we compare the string representation of the keys
45 // to avoid comparing the line numbers which are not relevant here.
46 if ((string) $key === (string) $pair['key']) {
47 return true;
48 }
49 }
50
51 return false;
52 }

References $key, and getKeyValuePairs().

+ Here is the call graph for this function:

Field Documentation

◆ $index

Twig_Node_Expression_Array::$index
protected

Definition at line 13 of file Array.php.


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