Skip to content

Instantly share code, notes, and snippets.

@xthiago
Forked from Ocramius/Rand.php
Created August 2, 2014 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xthiago/5b26c766edc67eb5a1b6 to your computer and use it in GitHub Desktop.
Save xthiago/5b26c766edc67eb5a1b6 to your computer and use it in GitHub Desktop.
<?php
$config = new \Doctrine\ORM\Configuration();
/** OTHER STUFF */
$config->addCustomNumericFunction('RAND', 'My\Custom\Doctrine2\Function\Rand');
/** CONTINUES */
<?php
namespace My\Custom\Doctrine2\Function;
/**
* RandFunction ::= "RAND" "(" ")"
*/
class Rand extends FunctionNode
{
public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return 'RAND()';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment