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

FunctionDeclaration() public method

FunctionDeclaration ::= FunctionsReturningStrings | FunctionsReturningNumerics | FunctionsReturningDatetime
public FunctionDeclaration ( )
    public function FunctionDeclaration()
    {
        $token = $this->_lexer->lookahead;
        $funcName = strtolower($token['value']);

        // Check for built-in functions first!
        if (isset(self::$_STRING_FUNCTIONS[$funcName])) {
            return $this->FunctionsReturningStrings();
        } else if (isset(self::$_NUMERIC_FUNCTIONS[$funcName])) {
            return $this->FunctionsReturningNumerics();
        } else if (isset(self::$_DATETIME_FUNCTIONS[$funcName])) {
            return $this->FunctionsReturningDatetime();
        }

        // Check for custom functions afterwards
        $config = $this->_em->getConfiguration();

        if ($config->getCustomStringFunction($funcName) !== null) {
            return $this->CustomFunctionsReturningStrings();
        } else if ($config->getCustomNumericFunction($funcName) !== null) {
            return $this->CustomFunctionsReturningNumerics();
        } else if ($config->getCustomDatetimeFunction($funcName) !== null) {
            return $this->CustomFunctionsReturningDatetime();
        }

        $this->syntaxError('known function', $token);
    }

Usage Example

Ejemplo n.º 1
0
 public function parse(\Doctrine\ORM\Query\Parser $parser)
 {
     $parser->match(Lexer::T_IDENTIFIER);
     $parser->match(Lexer::T_OPEN_PARENTHESIS);
     // Add the concat separator to the values array.
     $this->values[] = $parser->ArithmeticExpression();
     // Add the rest of the strings to the values array. CONCAT_WS must
     // be used with at least 2 strings not including the separator.
     $lexer = $parser->getLexer();
     while (count($this->values) < 3 || $lexer->lookahead['type'] == Lexer::T_COMMA) {
         $parser->match(Lexer::T_COMMA);
         $peek = $lexer->glimpse();
         $this->values[] = $peek['value'] == '(' ? $parser->FunctionDeclaration() : $parser->ArithmeticExpression();
     }
     while ($lexer->lookahead['type'] == Lexer::T_IDENTIFIER) {
         switch (strtolower($lexer->lookahead['value'])) {
             case 'notempty':
                 $parser->match(Lexer::T_IDENTIFIER);
                 $this->notEmpty = true;
                 break;
             default:
                 // Identifier not recognized (causes exception).
                 $parser->match(Lexer::T_CLOSE_PARENTHESIS);
                 break;
         }
     }
     $parser->match(Lexer::T_CLOSE_PARENTHESIS);
 }
All Usage Examples Of Doctrine\ORM\Query\Parser::FunctionDeclaration
Parser