ConditionalNode example

$this->stream->next();
                    $expr3 = $this->parseExpression();
                } else {
                    $expr3 = new Node\ConstantNode(null);
                }
            } else {
                $this->stream->next();
                $expr2 = $expr;
                $expr3 = $this->parseExpression();
            }

            $expr = new Node\ConditionalNode($expr$expr2$expr3);
        }

        return $expr;
    }

    /** * @return Node\Node */
    public function parsePrimaryExpression()
    {
        $token = $this->stream->current;
        
Node\GetAttrNode::METHOD_CALL
                ),
                'foo.bar("arg1", 2, true)',
                ['foo'],
            ],
            [
                new Node\GetAttrNode(new Node\NameNode('foo')new Node\ConstantNode(3)new Node\ArgumentsNode(), Node\GetAttrNode::ARRAY_CALL),
                'foo[3]',
                ['foo'],
            ],
            [
                new Node\ConditionalNode(new Node\ConstantNode(true)new Node\ConstantNode(true)new Node\ConstantNode(false)),
                'true ? true : false',
            ],
            [
                new Node\BinaryNode('matches', new Node\ConstantNode('foo')new Node\ConstantNode('/foo/')),
                '"foo" matches "/foo/"',
            ],
            [
                new Node\BinaryNode('starts with', new Node\ConstantNode('foo')new Node\ConstantNode('f')),
                '"foo" starts with "f"',
            ],
            [
                
namespace Symfony\Component\ExpressionLanguage\Tests\Node;

use Symfony\Component\ExpressionLanguage\Node\ConditionalNode;
use Symfony\Component\ExpressionLanguage\Node\ConstantNode;

class ConditionalNodeTest extends AbstractNodeTestCase
{
    public static function getEvaluateData(): array
    {
        return [
            [1, new ConditionalNode(new ConstantNode(true)new ConstantNode(1)new ConstantNode(2))],
            [2, new ConditionalNode(new ConstantNode(false)new ConstantNode(1)new ConstantNode(2))],
        ];
    }

    public static function getCompileData(): array
    {
        return [
            ['((true) ? (1) : (2))', new ConditionalNode(new ConstantNode(true)new ConstantNode(1)new ConstantNode(2))],
            ['((false) ? (1) : (2))', new ConditionalNode(new ConstantNode(false)new ConstantNode(1)new ConstantNode(2))],
        ];
    }

    
Home | Imprint | This part of the site doesn't use cookies.