Created
July 29, 2013 22:21
-
-
Save K-Phoen/6108436 to your computer and use it in GitHub Desktop.
MySQL REPLACE() for Doctrine2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | |
use Doctrine\ORM\Query\Lexer; | |
use Doctrine\ORM\Query\Parser; | |
use Doctrine\ORM\Query\SqlWalker; | |
/** | |
* REPLACE(str, from_str, to_str) | |
* "REPLACE" "(" StringPrimary "," StringPrimary "," StringPrimary ")" | |
*/ | |
class Replace extends FunctionNode | |
{ | |
protected $stringStr, $stringFromStr, $stringToStr; | |
public function getSql(SqlWalker $sqlWalker) | |
{ | |
return sprintf( | |
'REPLACE(%s, %s, %s)', | |
$sqlWalker->walkStringPrimary($this->stringStr), | |
$sqlWalker->walkStringPrimary($this->stringFromStr), | |
$sqlWalker->walkStringPrimary($this->stringToStr) | |
); | |
} | |
public function parse(Parser $parser) | |
{ | |
$parser->match(Lexer::T_IDENTIFIER); // REPLACE | |
$parser->match(Lexer::T_OPEN_PARENTHESIS); | |
$this->stringStr = $parser->StringPrimary(); // str | |
$parser->match(Lexer::T_COMMA); | |
$this->stringFromStr = $parser->StringPrimary(); // from_str | |
$parser->match(Lexer::T_COMMA); | |
$this->stringToStr = $parser->StringPrimary(); // to_str | |
$parser->match(Lexer::T_CLOSE_PARENTHESIS); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment