Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added getKeyValuePairs() on Twig_Node_Expression_Array

  • Loading branch information...
commit 542e9e76dcee6262ce734877c039bfd2d03560cf 1 parent 3f64f1d
@arnaud-lb authored
Showing with 17 additions and 3 deletions.
  1. +17 −3 lib/Twig/Node/Expression/Array.php
View
20 lib/Twig/Node/Expression/Array.php
@@ -15,6 +15,20 @@ public function __construct(array $elements, $lineno)
parent::__construct($elements, array(), $lineno);
}
+ public function getKeyValuePairs()
+ {
+ $pairs = array();
+
+ foreach (array_chunk($this->nodes, 2) as $pair) {
+ $pairs[] = array(
+ 'key' => $pair[0],
+ 'value' => $pair[1],
+ );
+ }
+
+ return $pairs;
+ }
+
/**
* Compiles the node to PHP.
*
@@ -24,16 +38,16 @@ public function compile(Twig_Compiler $compiler)
{
$compiler->raw('array(');
$first = true;
- foreach (array_chunk($this->nodes, 2) as $entry) {
+ foreach ($this->getKeyValuePairs() as $pair) {
if (!$first) {
$compiler->raw(', ');
}
$first = false;
$compiler
- ->subcompile($entry[0])
+ ->subcompile($pair['key'])
->raw(' => ')
- ->subcompile($entry[1])
+ ->subcompile($pair['value'])
;
}
$compiler->raw(')');
Please sign in to comment.
Something went wrong with that request. Please try again.