. */ declare(strict_types=1); namespace App\Doctrine\Functions; use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\ORM\Query\SqlWalker; /** * Similar to the regexp function, but with support for multi platform. */ class Regexp extends \DoctrineExtensions\Query\Mysql\Regexp { public function getSql(SqlWalker $sqlWalker): string { $platform = $sqlWalker->getConnection()->getDatabasePlatform(); // if ($platform instanceof AbstractMySQLPlatform || $platform instanceof SQLitePlatform) { $operator = 'REGEXP'; } elseif ($platform instanceof PostgreSQLPlatform) { //Use the case-insensitive operator, to have the same behavior as MySQL $operator = '~*'; } else { throw new \RuntimeException('Platform ' . gettype($platform) . ' does not support regular expressions.'); } return '(' . $this->value->dispatch($sqlWalker) . ' ' . $operator . ' ' . $this->regexp->dispatch($sqlWalker) . ')'; } }