<?php
namespace App\Doctrine\DBAL\Query\Mysql;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
/**
* "JSON_CONTAINS" "(" StringPrimary "," StringPrimary {"," StringExpression }* ")"
*/
class JsonContains extends FunctionNode
{
public $firstJson;
public $secondJson;
public $pathExpression = null;
/**
* @override
* @inheritdoc
*/
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
// $platform = $sqlWalker->getConnection()->getDatabasePlatform();
if ($this->pathExpression) {
return sprintf(
' JSON_CONTAINS(%s, %s, %s)',
$this->firstJson->dispatch($sqlWalker),
$this->secondJson->dispatch($sqlWalker),
$this->pathExpression->dispatch($sqlWalker)
);
}
return sprintf(
' JSON_CONTAINS(%s, %s)',
$this->firstJson->dispatch($sqlWalker),
$this->secondJson->dispatch($sqlWalker)
);
}
/**
* @override
* @inheritdoc
*/
public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->firstJson = $parser->StringPrimary();
$parser->match(Lexer::T_COMMA);
$this->secondJson = $parser->StringPrimary();
if ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) {
$parser->match(Lexer::T_COMMA);
$this->pathExpression = $parser->StringExpression();
}
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}