namibia
df0489e1eeeeab5a9bd44e1d84fce49924fe1bac
namibia / module / Utility / src / Utility / DoctrineFunction / UnixTimestamp.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
<?php namespace UVd\DoctrineFunction; use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\AST\Functions\FunctionNode; /** * UnixTimestamp * * Allows Doctrine 2.0 Query Language to execute a MySQL UNIX_FORMAT function * You must boostrap this function in your ORM as a DQLFunction. * * * UNIX_TIMESTAMP(TIMESTAMP) : @link http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp * * * PLEASE REMEMBER TO CHECK YOUR NAMESPACE * * @link labs.ultravioletdesign.co.uk * @author Rob Squires <rob@ultravioletdesign.co.uk> * * */ class UnixTimestamp extends FunctionNode { /* * holds the timestamp of the UNIX_TIMESTAMP DQL statement * @var mixed */ protected $dateExpression; /** * getSql - allows ORM to inject a UNIX_TIMESTAMP() statement into an SQL string being constructed * @param \Doctrine\ORM\Query\SqlWalker $sqlWalker * @return void */ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { return 'UNIX_TIMESTAMP(' . $sqlWalker->walkArithmeticExpression($this->dateExpression) . ')'; } /** * parse - allows DQL to breakdown the DQL string into a processable structure * @param \Doctrine\ORM\Query\Parser $parser */ public function parse(\Doctrine\ORM\Query\Parser $parser) { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); $this->dateExpression = $parser->ArithmeticExpression(); $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } |
Commits for namibiamodule/Utility/src/Utility/DoctrineFunction/UnixTimestamp.php
Revision | Author | Commited | Message |
---|---|---|---|
df0489 ... | Mark | Fri 14 Oct, 2016 10:01:00 +0000 | initial commit |