Created
September 5, 2015 11:45
-
-
Save cdunca/e657e4679c9dde6d5c09 to your computer and use it in GitHub Desktop.
Symfony - Doctrine dql extension for from_unixtime()
This file contains hidden or 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 AppBundle\DQL; | |
use Doctrine\ORM\Query\Lexer; | |
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | |
/** | |
* FromUnixtimeFunction ::= | |
* "unix_timestamp" "(" ArithmeticPrimary "," ArithmeticPrimary ")" | |
*/ | |
class FromUnixtimeFunction extends FunctionNode { | |
public $firstDateExpression = null; | |
public $secondDateExpression = null; | |
public function parse(\Doctrine\ORM\Query\Parser $parser) | |
{ | |
$parser->match(Lexer::T_IDENTIFIER); | |
$parser->match(Lexer::T_OPEN_PARENTHESIS); | |
$this->firstDateExpression = $parser->ArithmeticPrimary(); | |
$parser->match(Lexer::T_COMMA); | |
$this->secondDateExpression = $parser->ArithmeticPrimary(); | |
$parser->match(Lexer::T_CLOSE_PARENTHESIS); | |
} | |
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) | |
{ | |
return 'from_unixtime(' . | |
$this->firstDateExpression->dispatch($sqlWalker) . ', ' . | |
$this->secondDateExpression->dispatch($sqlWalker) . | |
')'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment