Skip to content

Commit

Permalink
Open bundle to doctrine/dbal v2.x and v3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Dumazeau committed Mar 14, 2022
1 parent 47929bd commit 475e0fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.1.12

- Open bundle to doctrine/dbal v2.x and v3.x

## Version 0.1.11

- Fix dependency to force doctrine/dbal v2, this lib is not compatible with v3 yet
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"require": {
"php": "^7.1 || ^8.0",
"doctrine/dbal": "^2.3",
"doctrine/dbal": "^2.3 || ^3.0",
"doctrine/doctrine-fixtures-bundle": "^3.4",
"richcongress/bundle-toolbox": "*",
"richcongress/fixture-test": "^0.1",
Expand Down
14 changes: 12 additions & 2 deletions src/Doctrine/EventListener/SqliteRegexOnPostConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,25 @@ public function postConnect(ConnectionEventArgs $args): void
return;
}

$connection->sqliteCreateFunction(
// For doctrine/dbal 2.x
if (\method_exists($connection, 'sqliteCreateFunction')) {
$nativeConnection = $connection;
// For doctrine/dbal 3.x
} elseif (\method_exists($connection, 'getNativeConnection')) {
$nativeConnection = $connection->getNativeConnection();
} else {
throw new \InvalidArgumentException('Unsupported doctrine pdo version.');
}

$nativeConnection->sqliteCreateFunction(
'REGEXP',
static function (string $regex, string $value): int {

return preg_match('/' . $regex . '/u', $value) ?: 0;
}
);

$connection->sqliteCreateFunction(
$nativeConnection->sqliteCreateFunction(
'REGEXP_REPLACE',
static function (string $value, string $regex, string $replace): string {
return preg_replace('/' . $regex . '/u', $replace, $value);
Expand Down

0 comments on commit 475e0fe

Please sign in to comment.