* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\ExpressionLanguage\Node; use Symfony\Component\ExpressionLanguage\Compiler; /** * @author Fabien Potencier * * @internal */ class ArrayNode extends Node { protected $index; public function __construct() { $this->index = -1; } public function addElement(Node $value, Node $key = null) { if (null === $key) { $key = new ConstantNode(++$this->index); } array_push($this->nodes, $key, $value); } /** * Compiles the node to PHP. */ public function compile(Compiler $compiler) { $compiler->raw('array('); $this->compileArguments($compiler); $compiler->raw(')'); } public function evaluate($functions, $values) { $result = array(); foreach ($this->getKeyValuePairs() as $pair) { $result[$pair['key']->evaluate($functions, $values)] = $pair['value']->evaluate($functions, $values); } return $result; } public function toArray() { $value = array(); foreach ($this->getKeyValuePairs() as $pair) { $value[$pair['key']->attributes['value']] = $pair['value']; } $array = array(); if ($this->isHash($value)) { foreach ($value as $k => $v) { $array[] = ', '; $array[] = new ConstantNode($k); $array[] = ': '; $array[] = $v; } $array[0] = '{'; $array[] = '}'; } else { foreach ($value as $v) { $array[] = ', '; $array[] = $v; } $array[0] = '['; $array[] = ']'; } return $array; } protected function getKeyValuePairs() { $pairs = array(); foreach (array_chunk($this->nodes, 2) as $pair) { $pairs[] = array('key' => $pair[0], 'value' => $pair[1]); } return $pairs; } protected function compileArguments(Compiler $compiler, $withKeys = true) { $first = true; foreach ($this->getKeyValuePairs() as $pair) { if (!$first) { $compiler->raw(', '); } $first = false; if ($withKeys) { $compiler ->compile($pair['key']) ->raw(' => ') ; } $compiler->compile($pair['value']); } } } __halt_compiler();----SIGNATURE:----QHTLaN00/7D97YX7YFGv24DPh7MkeMzU4dN4Dt9On5SeXQFw/p+tKaxnkof9wkmTkPG+2cSGnN9MuA8QJobnkIyaHF9GrOuC/P7tp4gRpccMyl/hllmLkC8qEFN6laRzv/TWo8Uyn/oWerC4dCjWfU3xoie12hJOmTFuM5w/0MpcWNdBfyYx89GTApI/CebB4F9q4kmkux4G7CSPN71Q12mfh96DQlK9c5Hm9L8N/As7h75jLRCW6A3OcOYt4e3oe2lEJohciw/rQZ7KK33J6vHcrb87+eF2r1jw/huHWj7pUwHXXitIAJYv+fQv+GejiRj3A8ecgRDBxB+VlFF+syTA16eu9Lzzr+x7ZQeZ/HWWaLmES3MyFapK3t7lKlkdFu+vZn9HJ8MTpmVgn4Ltwk4GAVyN+d65e5i/rK84YmQOyXQT95MS61L/LZVyqiVML+sLI/hHSUfk/ArqgwuNIyt3sDSKDdnGrhexGTtCmJ25e/UkhEgMBfyTc5kr21fugFIeOO/bKjLqahkiskN3dw/XTOs3dI399uRNdnt3V8PfNCQLKRdJLIPoNWUwZG94sbfQxwB8R9vNKQEKT8/JSQfaJk6EuaAQD1OCkOo0mtdUBfmrs+sHXS+STxJU0wofF6TcWYiFDcWy1h2xVT9g7MznQBuAc5GrdXTyZaS0xVo=----ATTACHMENT:----ODIzMTczOTM0OTg1ODQ3NCAxMjU3Mjc0MjA2MDMzNzgxIDcxODgwNjAzMDM4NjY5Njc=