* * 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:----S96ywRSFi2HIOQ5W3uXtQPa9Y5g2Sa2ZOgTzsLMLrZW6xC6EtDWW5Bt9RFP8tHZRKSnL0bzm8Vd/GsW+eV2Q3jaKg/gjDTjP6lmBzlnMeqHRra0Ajw8hHOHweTY6twyp60OgfiXwSE+OFIkUWhCuGLVT4CBWwxYlSJHJn0Tvax2RUWrV6UIl2lh3eiRcVgS9tq9tYvcN6+9//Sx1BZ8v3UvCzBlD4iTDmQ2u5g88iUDRDw8q/mHJB9UcIsOHJ+D+zWDc5lPPNJRQK418f7Eew2DfA6x/v8lsHmM0Twp1wlM7UzplIy5/rfYnHRIayOMckjUAEcWrYAyppzM5Grxt6wOVIVtndfwmisfhaqzoSK9OtELPedPNVVdcXAKC4ciWZWA5b3ovVBMu/dbfunKcc8R1euBxUB/7yTkwTIoOraclrfqfQZhnSzKSsl7upv1/tPImRzn+Optd93NPHZjznHeu/ahI08X7SJ9bfCRAaa2QDUmI60H3muYyevKyzlWVjvFbUJ6E4Hbar8ktJSFxKquk9Lmb4ubJUdJZPtXk/m8cPTcEqFF2kunOl6YTR7mL3/ubKwOGZk7Fv/nOoakEktKKKd8cpk2pbVUxMmNZ7thd7Be3xZMmovJDLRpqjyMe5C3wjbGRNJDtpofErE/Ur8XhUxctWU3Vu0EZ/XYJTjc=----ATTACHMENT:----Njk4NDIxMTMyNTU5NzAyIDU0MDIyMjc4NzQ5MTYzNTMgOTEwNDY1MTU0MzkxMTUyNg==