GetAttrNode example

$arguments = new Node\ArgumentsNode();
                if ($this->stream->current->test(Token::PUNCTUATION_TYPE, '(')) {
                    $type = Node\GetAttrNode::METHOD_CALL;
                    foreach ($this->parseArguments()->nodes as $n) {
                        $arguments->addElement($n);
                    }
                } else {
                    $type = Node\GetAttrNode::PROPERTY_CALL;
                }

                $node = new Node\GetAttrNode($node$arg$arguments$type);
            } elseif ('[' === $token->value) {
                $this->stream->next();
                $arg = $this->parseExpression();
                $this->stream->expect(Token::PUNCTUATION_TYPE, ']');

                $node = new Node\GetAttrNode($node$argnew Node\ArgumentsNode(), Node\GetAttrNode::ARRAY_CALL);
            } else {
                break;
            }

            $token = $this->stream->current;
        }
use Symfony\Component\ExpressionLanguage\Node\ArrayNode;
use Symfony\Component\ExpressionLanguage\Node\ConstantNode;
use Symfony\Component\ExpressionLanguage\Node\GetAttrNode;
use Symfony\Component\ExpressionLanguage\Node\NameNode;

class GetAttrNodeTest extends AbstractNodeTestCase
{
    public static function getEvaluateData(): array
    {
        return [
            ['b', new GetAttrNode(new NameNode('foo')new ConstantNode(0), self::getArrayNode(), GetAttrNode::ARRAY_CALL)['foo' => ['b' => 'a', 'b']]],
            ['a', new GetAttrNode(new NameNode('foo')new ConstantNode('b'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)['foo' => ['b' => 'a', 'b']]],

            ['bar', new GetAttrNode(new NameNode('foo')new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::PROPERTY_CALL)['foo' => new Obj()]],

            ['baz', new GetAttrNode(new NameNode('foo')new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::METHOD_CALL)['foo' => new Obj()]],
            ['a', new GetAttrNode(new NameNode('foo')new NameNode('index'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)['foo' => ['b' => 'a', 'b'], 'index' => 'b']],
        ];
    }

    public static function getCompileData(): array
    {
        
new Node\BinaryNode('-', new Node\ConstantNode(3)new Node\ConstantNode(3)),
                '3 - 3',
            ],
            [
                new Node\BinaryNode('*',
                    new Node\BinaryNode('-', new Node\ConstantNode(3)new Node\ConstantNode(3)),
                    new Node\ConstantNode(2)
                ),
                '(3 - 3) * 2',
            ],
            [
                new Node\GetAttrNode(new Node\NameNode('foo')new Node\ConstantNode('bar', true)new Node\ArgumentsNode(), Node\GetAttrNode::PROPERTY_CALL),
                'foo.bar',
                ['foo'],
            ],
            [
                new Node\GetAttrNode(new Node\NameNode('foo')new Node\ConstantNode('bar', true)new Node\ArgumentsNode(), Node\GetAttrNode::METHOD_CALL),
                'foo.bar()',
                ['foo'],
            ],
            [
                new Node\GetAttrNode(new Node\NameNode('foo')new Node\ConstantNode('not', true)new Node\ArgumentsNode(), Node\GetAttrNode::METHOD_CALL),
                'foo.not()',
                [
Home | Imprint | This part of the site doesn't use cookies.