Show a proper error message table when encountering an invalid regex statement on SQLite

This is related to #289
This commit is contained in:
Jan Böhmer 2023-05-09 00:26:40 +02:00
parent 2c33b381c1
commit b0ab43c39a
3 changed files with 99 additions and 13 deletions

View file

@ -20,6 +20,7 @@
namespace App\Doctrine;
use App\Exceptions\InvalidRegexException;
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
@ -43,7 +44,11 @@ class SQLiteRegexExtension implements EventSubscriberInterface
//Ensure that the function really exists on the connection, as it is marked as experimental according to PHP documentation
if($native_connection instanceof \PDO && method_exists($native_connection, 'sqliteCreateFunction' )) {
$native_connection->sqliteCreateFunction('REGEXP', function ($pattern, $value) {
return (false !== mb_ereg($pattern, $value)) ? 1 : 0;
try {
return (false !== mb_ereg($pattern, $value)) ? 1 : 0;
} catch (\ErrorException $e) {
throw InvalidRegexException::fromMBRegexError($e);
}
});
}
}