]> Raphaƫl G. Git Repositories - blogbundle/blob - Dql/JsonFunction.php
Fix default bind ciphersuites and options
[blogbundle] / Dql / JsonFunction.php
1 <?php
2
3 namespace Rapsys\BlogBundle\Dql;
4
5 use \Doctrine\ORM\Query\Lexer;
6
7 class JsonFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode {
8 public $keyExpression = null;
9 public $valueExpression = null;
10
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();
15
16 if (Lexer::T_COMMA === $parser->getLexer()->lookahead['type']) {
17 $parser->match(Lexer::T_COMMA);
18 $this->valueExpression = $parser->ArithmeticPrimary();
19 }
20
21 $parser->match(Lexer::T_CLOSE_PARENTHESIS);
22 }
23
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).', \'"\', \'\\\\"\'), \'"\')), \'}\')';
27 }
28 return 'CONCAT(\'[\', GROUP_CONCAT(REPLACE('.$this->keyExpression->dispatch($sqlWalker).', \'"\', \'\\\\"\')), \']\')';
29 }
30 }