. */ declare(strict_types=1); namespace App\Doctrine\Functions; use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; use Doctrine\DBAL\Platforms\MariaDBPlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; 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; class Natsort extends FunctionNode { private ?Node $field = null; public function parse(Parser $parser): void { $parser->match(TokenType::T_IDENTIFIER); $parser->match(TokenType::T_OPEN_PARENTHESIS); $this->field = $parser->ArithmeticExpression(); $parser->match(TokenType::T_CLOSE_PARENTHESIS); } public function getSql(SqlWalker $sqlWalker): string { assert($this->field !== null, 'Field is not set'); $platform = $sqlWalker->getConnection()->getDatabasePlatform(); if ($platform instanceof PostgreSQLPlatform) { return $this->field->dispatch($sqlWalker) . ' COLLATE numeric'; } /*if ($platform instanceof MariaDBPlatform && $sqlWalker->getConnection()->getServerVersion()) { }*/ //For every other platform, return the field as is return $this->field->dispatch($sqlWalker); } }