Created
March 9, 2015 04:41
-
-
Save 77web/43da0a19414f22d9614b to your computer and use it in GitHub Desktop.
メモ:Doctrine2でmysqlのYEAR,Monthを使えるようにするためのExtension
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 Nanaweb\Doctrine\DateFunctionExtension; | |
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | |
use Doctrine\ORM\Query\Lexer; | |
use Doctrine\ORM\Query\Parser; | |
use Doctrine\ORM\Query\SqlWalker; | |
/** | |
* MonthFunction ::= | |
* "MONTH" "(" ArithmeticPrimary ")" | |
*/ | |
class Month extends FunctionNode | |
{ | |
public $dateExpression = null; | |
public function parse(Parser $parser) | |
{ | |
$parser->match(Lexer::T_IDENTIFIER); | |
$parser->match(Lexer::T_OPEN_PARENTHESIS); | |
$this->dateExpression = $parser->ArithmeticPrimary(); | |
$parser->match(Lexer::T_CLOSE_PARENTHESIS); | |
} | |
public function getSql(SqlWalker $sqlWalker) | |
{ | |
return 'MONTH('.$this->dateExpression->dispatch($sqlWalker).')'; | |
} | |
} |
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 Nanaweb\Doctrine\DateFunctionExtension; | |
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | |
use Doctrine\ORM\Query\Lexer; | |
use Doctrine\ORM\Query\Parser; | |
use Doctrine\ORM\Query\SqlWalker; | |
/** | |
* MonthFunction ::= | |
* "YEAR" "(" ArithmeticPrimary ")" | |
*/ | |
class Year extends FunctionNode | |
{ | |
public $dateExpression = null; | |
public function parse(Parser $parser) | |
{ | |
$parser->match(Lexer::T_IDENTIFIER); | |
$parser->match(Lexer::T_OPEN_PARENTHESIS); | |
$this->dateExpression = $parser->ArithmeticPrimary(); | |
$parser->match(Lexer::T_CLOSE_PARENTHESIS); | |
} | |
public function getSql(SqlWalker $sqlWalker) | |
{ | |
return 'YEAR('.$this->dateExpression->dispatch($sqlWalker).')'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment