3 namespace Rapsys\BlogBundle\Dql
;
5 use \Doctrine\ORM\Query\Lexer
;
7 class JsonFunction
extends \Doctrine\ORM\Query\AST\Functions\FunctionNode
{
8 public $keyExpression = null;
9 public $valueExpression = null;
11 public function parse(\Doctrine\ORM\Query\Parser
$parser) {
12 $parser->match(Lexer
::T_IDENTIFIER
);
13 $parser->match(Lexer
::T_OPEN_PARENTHESIS
);
14 $this->keyExpression
= $parser->ArithmeticPrimary();
16 if (Lexer
::T_COMMA
=== $parser->getLexer()->lookahead
['type']) {
17 $parser->match(Lexer
::T_COMMA
);
18 $this->valueExpression
= $parser->ArithmeticPrimary();
21 $parser->match(Lexer
::T_CLOSE_PARENTHESIS
);
24 public function getSql(\Doctrine\ORM\Query\SqlWalker
$sqlWalker) {
25 if (null !== $this->valueExpression
) {
26 return 'CONCAT(\'{\', GROUP_CONCAT(CONCAT(\'"\', REPLACE('.$this
->keyExpression
->dispatch($sqlWalker
).', \'"\', \'\\\\"\'), \'": "\', REPLACE('.$this
->valueExpression
->dispatch($sqlWalker
).', \'"\', \'\\\\"\'), \'"\')), \'}\')';
28 return 'CONCAT(\'[\', GROUP_CONCAT(REPLACE('.$this->keyExpression
->dispatch($sqlWalker).', \'"\', \'\\\\"\')), \']\')';