mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 20:06:31 +00:00
added getKeyValuePairs() on Twig_Node_Expression_Array
This commit is contained in:
@@ -15,6 +15,20 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
|
|||||||
parent::__construct($elements, array(), $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.
|
* Compiles the node to PHP.
|
||||||
*
|
*
|
||||||
@@ -24,16 +38,16 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
|
|||||||
{
|
{
|
||||||
$compiler->raw('array(');
|
$compiler->raw('array(');
|
||||||
$first = true;
|
$first = true;
|
||||||
foreach (array_chunk($this->nodes, 2) as $entry) {
|
foreach ($this->getKeyValuePairs() as $pair) {
|
||||||
if (!$first) {
|
if (!$first) {
|
||||||
$compiler->raw(', ');
|
$compiler->raw(', ');
|
||||||
}
|
}
|
||||||
$first = false;
|
$first = false;
|
||||||
|
|
||||||
$compiler
|
$compiler
|
||||||
->subcompile($entry[0])
|
->subcompile($pair['key'])
|
||||||
->raw(' => ')
|
->raw(' => ')
|
||||||
->subcompile($entry[1])
|
->subcompile($pair['value'])
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
$compiler->raw(')');
|
$compiler->raw(')');
|
||||||
|
|||||||
Reference in New Issue
Block a user