Doctrine\ORM\Query\Parser::SimpleConditionalExpression PHP Method

SimpleConditionalExpression() public method

SimpleConditionalExpression ::= ComparisonExpression | BetweenExpression | LikeExpression | InExpression | NullComparisonExpression | ExistsExpression | EmptyCollectionComparisonExpression | CollectionMemberExpression | InstanceOfExpression
    public function SimpleConditionalExpression()
    {
        if ($this->_lexer->isNextToken(Lexer::T_NOT)) {
            $token = $this->_lexer->glimpse();
        } else {
            $token = $this->_lexer->lookahead;
        }

        if ($token['type'] === Lexer::T_EXISTS) {
            return $this->ExistsExpression();
        }

        $peek = $this->_lexer->glimpse();

        if ($token['type'] === Lexer::T_IDENTIFIER || $token['type'] === Lexer::T_INPUT_PARAMETER) {
            if ($peek['value'] == '(') {
                // Peek beyond the matching closing paranthesis ')'
                $this->_lexer->peek();
                $token = $this->_peekBeyondClosingParenthesis();
            } else {
                // Peek beyond the PathExpression (or InputParameter)
                $peek = $this->_lexer->peek();

                while ($peek['value'] === '.') {
                    $this->_lexer->peek();
                    $peek = $this->_lexer->peek();
                }

                // Also peek beyond a NOT if there is one
                if ($peek['type'] === Lexer::T_NOT) {
                    $peek = $this->_lexer->peek();
                }

                $token = $peek;

                // We need to go even further in case of IS (differenciate between NULL and EMPTY)
                $lookahead = $this->_lexer->peek();

                // Also peek beyond a NOT if there is one
                if ($lookahead['type'] === Lexer::T_NOT) {
                    $lookahead = $this->_lexer->peek();
                }

                $this->_lexer->resetPeek();
            }
        }

        switch ($token['type']) {
            case Lexer::T_BETWEEN:
                return $this->BetweenExpression();
            case Lexer::T_LIKE:
                return $this->LikeExpression();
            case Lexer::T_IN:
                return $this->InExpression();
            case Lexer::T_INSTANCE:
                return $this->InstanceOfExpression();
            case Lexer::T_IS:
                if ($lookahead['type'] == Lexer::T_NULL) {
                    return $this->NullComparisonExpression();
                }
                return $this->EmptyCollectionComparisonExpression();
            case Lexer::T_MEMBER:
                return $this->CollectionMemberExpression();
            default:
                return $this->ComparisonExpression();
        }
    }

Usage Example

コード例 #1
0
ファイル: IfStatement.php プロジェクト: hisie/UsefulBundle
 public function parse(Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     // (2)
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     // (3)
     $this->f1 = $parser->SimpleConditionalExpression();
     // (4)
     $parser->match(Lexer::T_COMMA);
     // (5)
     $this->f2 = $parser->SimpleArithmeticExpression();
     // (6)
     $parser->match(Lexer::T_COMMA);
     // (5)
     $this->f3 = $parser->SimpleArithmeticExpression();
     // (6)
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
     // (3)
 }
Parser