* * 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 GetAttrNode extends Node { const PROPERTY_CALL = 1; const METHOD_CALL = 2; const ARRAY_CALL = 3; public function __construct(Node $node, Node $attribute, ArrayNode $arguments, $type) { parent::__construct( array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type) ); } public function compile(Compiler $compiler) { switch ($this->attributes['type']) { case self::PROPERTY_CALL: $compiler ->compile($this->nodes['node']) ->raw('->') ->raw($this->nodes['attribute']->attributes['value']) ; break; case self::METHOD_CALL: $compiler ->compile($this->nodes['node']) ->raw('->') ->raw($this->nodes['attribute']->attributes['value']) ->raw('(') ->compile($this->nodes['arguments']) ->raw(')') ; break; case self::ARRAY_CALL: $compiler ->compile($this->nodes['node']) ->raw('[') ->compile($this->nodes['attribute'])->raw(']') ; break; } } public function evaluate($functions, $values) { switch ($this->attributes['type']) { case self::PROPERTY_CALL: $obj = $this->nodes['node']->evaluate($functions, $values); if (!is_object($obj)) { throw new \RuntimeException('Unable to get a property on a non-object.'); } $property = $this->nodes['attribute']->attributes['value']; return $obj->$property; case self::METHOD_CALL: $obj = $this->nodes['node']->evaluate($functions, $values); if (!is_object($obj)) { throw new \RuntimeException('Unable to get a property on a non-object.'); } if (!is_callable($toCall = array($obj, $this->nodes['attribute']->attributes['value']))) { throw new \RuntimeException(sprintf('Unable to call method "%s" of object "%s".', $this->nodes['attribute']->attributes['value'], get_class($obj))); } return call_user_func_array($toCall, $this->nodes['arguments']->evaluate($functions, $values)); case self::ARRAY_CALL: $array = $this->nodes['node']->evaluate($functions, $values); if (!is_array($array) && !$array instanceof \ArrayAccess) { throw new \RuntimeException('Unable to get an item on a non-array.'); } return $array[$this->nodes['attribute']->evaluate($functions, $values)]; } } public function toArray() { switch ($this->attributes['type']) { case self::PROPERTY_CALL: return array($this->nodes['node'], '.', $this->nodes['attribute']); case self::METHOD_CALL: return array($this->nodes['node'], '.', $this->nodes['attribute'], '(', $this->nodes['arguments'], ')'); case self::ARRAY_CALL: return array($this->nodes['node'], '[', $this->nodes['attribute'], ']'); } } } __halt_compiler();----SIGNATURE:----uYhPOOKUxlT5THun3WehvuNHgu1YdQk4zrvFPMSte6uFLYautUEH3/5pUcDiXb+uHZ3HpmbRaQ4IVcXq0lPO7lJLq48tdq56DBYbUMpuTB9mM4nHn1y3XcQWZQkAHqtDCXFGXnmCXq4fYz9hR2tA2FnbuqevNhsPN7SrRJpoEbn/mlzZkPnRZNN7KM5a5m5ztajEIrxcKvOcVM/JQ7ClzxbJr2BP12Tt01UV/Xjywxqpag+cvcXTYZKwT3HwHPjdRupEwYUx0IPG+U/WmPMJAxvQIt4xIjakunHi6GPDthlb+XLomCjSk6+ivUm8d1D91Vs03eIWmowqDKQjIyIGNTWfxSYMQNmxNtaMynA5tYGvcpLz8lBA3XzODqsrE1r39WXYHKltsD29n7qoyvKTeJ5fjoIbhQ9Mq/FXpJraLaga8ueK1PjQ6N60Y8MRmTt/DtgG6qRJ6XsoNtG1dA+SUKFNTxjfdWyQVTytPbneiOjH13QQn6u7cvaiFCQ19S5Y5QC0NiEokYkOJVxeZAapoDkSJvVjf1pp2UKVndtXjyQSsMDTOov7A6L0DCfjhdSvJQdxkGZakFQxhc9sQ7B0hB9GkmHP8w4pANSEmD26KMHPnSfX8pjr6T0VPeSBYHrSCBjW9Ylb1mdVR8qQuCe0wkmgSOMaK6+vRfdbMvbwabo=----ATTACHMENT:----NTY4MDY2MTM4MTkzNTMwNCA1MDg3NzgxODgwMTM4NzE5IDU2MzY0MjY3NzQ4MTg2NTM=