feat: add tag filtering to blog posts and implement JSON_CONTAINS DQL function

This commit is contained in:
hamed
2026-06-21 17:34:07 +03:30
parent 91cfb64217
commit 21b6c583c0
5 changed files with 69 additions and 10 deletions
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace App\Shared\Doctrine;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;
/**
* JSON_CONTAINS(json_doc, candidate) DQL function for MariaDB/MySQL.
* Usage: WHERE JSON_CONTAINS(b.tags, :tag) = 1
*/
class JsonContains extends FunctionNode
{
private Node $jsonDoc;
private Node $candidate;
public function parse(Parser $parser): void
{
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);
$this->jsonDoc = $parser->StringPrimary();
$parser->match(TokenType::T_COMMA);
$this->candidate = $parser->StringPrimary();
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
public function getSql(SqlWalker $sqlWalker): string
{
return sprintf(
'JSON_CONTAINS(%s, %s)',
$this->jsonDoc->dispatch($sqlWalker),
$this->candidate->dispatch($sqlWalker)
);
}
}