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

SelectExpression() public method

SelectExpression ::= IdentificationVariable | StateFieldPathExpression | (AggregateExpression | "(" Subselect ")" | ScalarExpression) [["AS"] AliasResultVariable]
public SelectExpression ( ) : Doctrine\ORM\Query\AST\SelectExpression
return Doctrine\ORM\Query\AST\SelectExpression
    public function SelectExpression()
    {
        $expression = null;
        $identVariable = null;
        $fieldAliasIdentificationVariable = null;
        $peek = $this->_lexer->glimpse();

        $supportsAlias = true;

        if ($peek['value'] != '(' && $this->_lexer->lookahead['type'] === Lexer::T_IDENTIFIER) {
            if ($peek['value'] == '.') {
                // ScalarExpression
                $expression = $this->ScalarExpression();
            } else {
                $supportsAlias = false;
                $expression = $identVariable = $this->IdentificationVariable();
            }
        } else if ($this->_lexer->lookahead['value'] == '(') {
            if ($peek['type'] == Lexer::T_SELECT) {
                // Subselect
                $this->match(Lexer::T_OPEN_PARENTHESIS);
                $expression = $this->Subselect();
                $this->match(Lexer::T_CLOSE_PARENTHESIS);
            } else {
                // Shortcut: ScalarExpression => SimpleArithmeticExpression
                $expression = $this->SimpleArithmeticExpression();
            }
        } else if ($this->_isFunction()) {
            $this->_lexer->peek(); // "("
            $beyond = $this->_peekBeyondClosingParenthesis();

            if ($this->_isMathOperator($beyond)) {
                $expression = $this->ScalarExpression();
            } else if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) {
                $expression = $this->AggregateExpression();
            } else {
                // Shortcut: ScalarExpression => Function
                $expression = $this->FunctionDeclaration();
            }
        } else if ($this->_lexer->lookahead['type'] == Lexer::T_PARTIAL) {
            $supportsAlias = false;
            $expression = $this->PartialObjectExpression();
            $identVariable = $expression->identificationVariable;
        } else if ($this->_lexer->lookahead['type'] == Lexer::T_INTEGER ||
                $this->_lexer->lookahead['type'] == Lexer::T_FLOAT) {
            // Shortcut: ScalarExpression => SimpleArithmeticExpression
            $expression = $this->SimpleArithmeticExpression();
        } else {
            $this->syntaxError('IdentificationVariable | StateFieldPathExpression'
                    . ' | AggregateExpression | "(" Subselect ")" | ScalarExpression',
                    $this->_lexer->lookahead);
        }

        if ($supportsAlias) {
            if ($this->_lexer->isNextToken(Lexer::T_AS)) {
                $this->match(Lexer::T_AS);
            }

            if ($this->_lexer->isNextToken(Lexer::T_IDENTIFIER)) {
                $token = $this->_lexer->lookahead;
                $fieldAliasIdentificationVariable = $this->AliasResultVariable();

                // Include AliasResultVariable in query components.
                $this->_queryComponents[$fieldAliasIdentificationVariable] = array(
                    'resultVariable' => $expression,
                    'nestingLevel'   => $this->_nestingLevel,
                    'token'          => $token,
                );
            }
        }

        $expr = new AST\SelectExpression($expression, $fieldAliasIdentificationVariable);
        if (!$supportsAlias) {
            $this->_identVariableExpressions[$identVariable] = $expr;
        }
        return $expr;
    }
Parser