From: Raphaƫl Gertz Date: Sun, 25 Feb 2018 05:05:26 +0000 (+0100) Subject: Add dql json function X-Git-Tag: 0.1~63 X-Git-Url: https://git.rapsys.eu/blogbundle/commitdiff_plain/d469b7bf0d80ae60fe5536c50333d8145e02b3e4 Add dql json function --- diff --git a/Dql/JsonFunction.php b/Dql/JsonFunction.php new file mode 100644 index 0000000..06e314d --- /dev/null +++ b/Dql/JsonFunction.php @@ -0,0 +1,30 @@ +match(Lexer::T_IDENTIFIER); + $parser->match(Lexer::T_OPEN_PARENTHESIS); + $this->keyExpression = $parser->ArithmeticPrimary(); + + if (Lexer::T_COMMA === $parser->getLexer()->lookahead['type']) { + $parser->match(Lexer::T_COMMA); + $this->valueExpression = $parser->ArithmeticPrimary(); + } + + $parser->match(Lexer::T_CLOSE_PARENTHESIS); + } + + public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { + if (null !== $this->valueExpression) { + return 'CONCAT(\'{\', GROUP_CONCAT(CONCAT(\'"\', REPLACE('.$this->keyExpression->dispatch($sqlWalker).', \'"\', \'\\\\"\'), \'": "\', REPLACE('.$this->valueExpression->dispatch($sqlWalker).', \'"\', \'\\\\"\'), \'"\')), \'}\')'; + } + return 'CONCAT(\'[\', GROUP_CONCAT(REPLACE('.$this->keyExpression->dispatch($sqlWalker).', \'"\', \'\\\\"\')), \']\')'; + } +}