forked from beberlei/DoctrineExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding YearMonth function (beberlei#266)
Adding MySql YEARMONTH Function
- Loading branch information
1 parent
a7957e5
commit f592c49
Showing
4 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,4 @@ | |
"dev-master": "1.0-dev" | ||
} | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* | ||
* DoctrineExtensions Mysql Function Pack | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so I can send you a copy immediately. | ||
*/ | ||
|
||
namespace DoctrineExtensions\Query\Mysql; | ||
|
||
use Doctrine\ORM\Query\Lexer; | ||
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | ||
|
||
class YearMonth extends FunctionNode | ||
{ | ||
public $date; | ||
|
||
/** | ||
* @override | ||
*/ | ||
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) | ||
{ | ||
return sprintf( | ||
'EXTRACT(YEAR_MONTH FROM %s)', | ||
$sqlWalker->walkArithmeticPrimary($this->date) | ||
); | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
public function parse(\Doctrine\ORM\Query\Parser $parser) | ||
{ | ||
$parser->match(Lexer::T_IDENTIFIER); | ||
$parser->match(Lexer::T_OPEN_PARENTHESIS); | ||
$this->date = $parser->ArithmeticPrimary(); | ||
$parser->match(Lexer::T_CLOSE_PARENTHESIS); | ||
} | ||
} |