From d469b7bf0d80ae60fe5536c50333d8145e02b3e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Sun, 25 Feb 2018 06:05:26 +0100 Subject: [PATCH] Add dql json function --- Dql/JsonFunction.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Dql/JsonFunction.php 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).', \'"\', \'\\\\"\')), \']\')'; + } +} -- 2.41.1