SimpleConditionalExpression.php 1.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
<?php
/**
 * SimpleConditionalExpression =
 *     Expression (ComparisonExpression | BetweenExpression | LikeExpression |
 *     InExpression | NullComparisonExpression | QuantifiedExpression) |
 *     ExistsExpression
 */
class Doctrine_Query_Production_SimpleConditionalExpression extends Doctrine_Query_Production
{
    protected function _getExpressionType() {
        if ($this->_isNextToken(Doctrine_Query_Token::T_NOT)) {
            $token = $this->_parser->getScanner()->peek();
            $this->_parser->getScanner()->resetPeek();
        } else {
            $token = $this->_parser->lookahead;
        }

        return $token['type'];
    }

    public function execute(array $params = array())
    {
        if ($this->_getExpressionType() === Doctrine_Query_Token::T_EXISTS) {
            $this->ExistsExpression();
        } else {
            $this->Expression();

            switch ($this->_getExpressionType()) {
                case Doctrine_Query_Token::T_BETWEEN:
                    $this->BetweenExpression();
                break;
                case Doctrine_Query_Token::T_LIKE:
                    $this->LikeExpression();
                break;
                case Doctrine_Query_Token::T_IN:
                    $this->InExpression();
                break;
                case Doctrine_Query_Token::T_IS:
                    $this->NullComparisonExpression();
                break;
                case Doctrine_Query_Token::T_NONE:
                    $this->ComparisonExpression();
                break;
                default:
                    $this->_parser->syntaxError();
            }
        }

    }
}