2012-03-18 76 views

回答

2

你可以自己實現它像this

+0

非常感謝你 – Stefano 2012-03-18 20:27:09

+0

@Stefano歡迎。 – 2012-03-18 20:28:23

0
<?php 

use Doctrine\ORM\Query\AST\Functions\FunctionNode; 
use Doctrine\ORM\Query\Lexer; 

/** 
* JsonbExistence ::= "LEFT('a', 'b')" 
* 
* This will be converted to: "LEFT('a', 'b')" 
* 
*/ 
class LeftFunction extends FunctionNode 
{ 

    public $column = null; 
    public $regexp = null; 

    public function parse(\Doctrine\ORM\Query\Parser $parser) 
    { 
     $parser->match(Lexer::T_IDENTIFIER); 
     $parser->match(Lexer::T_OPEN_PARENTHESIS); 
     $this->column = $parser->ArithmeticPrimary(); 
     $parser->match(Lexer::T_COMMA); 
     $this->regexp = $parser->ArithmeticPrimary(); 
     $parser->match(Lexer::T_CLOSE_PARENTHESIS); 
    } 

    public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) 
    { 
     return sprintf('LEFT(%s, %s)', $this->column->dispatch($sqlWalker), $this->regexp->dispatch($sqlWalker)); 
    } 
}