Created
August 5, 2015 11:25
-
-
Save Kryniol/901255742078bdb8aa1d to your computer and use it in GitHub Desktop.
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 | |
namespace MyProject\MyBundle\Doctrine\Functions; | |
use Doctrine\ORM\Query\AST\ArithmeticExpression; | |
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | |
use Doctrine\ORM\Query\AST\Node; | |
use Doctrine\ORM\Query\Lexer; | |
use Doctrine\ORM\Query\Parser; | |
use Doctrine\ORM\Query\SqlWalker; | |
class Like extends FunctionNode | |
{ | |
/** | |
* @var ArithmeticExpression | |
*/ | |
public $value; | |
/** | |
* @var Node | |
*/ | |
public $matcher; | |
/** | |
* {@inheritdoc} | |
*/ | |
public function parse(Parser $parser) | |
{ | |
$parser->match(Lexer::T_IDENTIFIER); | |
$parser->match(Lexer::T_OPEN_PARENTHESIS); | |
$this->value = $parser->ArithmeticExpression(); | |
$parser->match(Lexer::T_COMMA); | |
$this->matcher = $parser->StringExpression(); | |
$parser->match(Lexer::T_CLOSE_PARENTHESIS); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getSql(SqlWalker $sqlWalker) | |
{ | |
return sprintf( | |
'(%s LIKE %s)', | |
$this->value->dispatch($sqlWalker), | |
$this->matcher->dispatch($sqlWalker) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment