8000 Use TypeError & fix DBAL platform detection · symfony/symfony@952ca0e · GitHub
[go: up one dir, main page]

Skip to content

Commit 952ca0e

Browse files
committed
Use TypeError & fix DBAL platform detection
1 parent f7d493a commit 952ca0e

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

src/Symfony/Component/Lock/Store/DoctrineDbalPostgreSqlStore.php

+8-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Symfony\Component\Lock\Exception\InvalidArgumentException;
2020
use Symfony\Component\Lock\Exception\LockConflictedException;
2121
use Symfony\Component\Lock\Key;
22-
use Symfony\Component\Lock\PersistingStoreInterface;
22+
use Symfony\Component\Lock\SharedLockStoreInterface;
2323

2424
/**
2525
* DoctrineDbalPostgreSqlStore is a PersistingStoreInterface implementation using
@@ -53,7 +53,7 @@ public function __construct($connOrDsn)
5353
}
5454
$this->conn = DriverManager::getConnection(['url' => $this->filterDsn($connOrDsn)]);
5555
} else {
56-
throw new InvalidArgumentException(sprintf('"%s" requires Doctrine\DBAL\Connection instance or DSN string as first argument, "%s" given.', __CLASS__, get_debug_type($connOrDsn)));
56+
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be %s or string, "%s" given.', Connection::class, __METHOD__, get_debug_type($connOrDsn)));
5757
}
5858
}
5959

@@ -207,8 +207,9 @@ private function unlockShared(Key $key): void
207207

208208
/**
209209
* Check driver and remove scheme extension from DSN.
210-
* Input: pgsql+advisory://server/
211-
* Output: pgsql://server/
210+
* Input: pgsql+advisory://server/
211+
* Output: pgsql://server/
212+
*
212213
* @throws InvalidArgumentException when driver is not supported.
213214
*/
214215
private function filterDsn(string $dsn): string
@@ -218,20 +219,15 @@ private function filterDsn(string $dsn): string
218219
}
219220

220221
[$scheme, $rest] = explode(':', $dsn,2);
221-
222-
$driver = $scheme;
223-
if (str_contains($scheme, '+')) {
224-
[$driver] = explode('+', $scheme, 2);
225-
}
226-
227-
if (!in_array($driver, ['pgsql', 'postgres', 'postgresql'])) {
222+
$driver = strtok($scheme, '+');
223+
if (!\in_array($driver, ['pgsql', 'postgres', 'postgresql'])) {
228224
throw new InvalidArgumentException(sprintf('The adapter "%s" does not support the "%s" driver.', __CLASS__, $driver));
229225
}
230226

231227
return sprintf('%s:%s', $driver, $rest);
232228
}
233229

234-
private function getInternalStore(): PersistingStoreInterface
230+
private function getInternalStore(): SharedLockStoreInterface
235231
{
236232
$namespace = spl_object_hash($this->conn);
237233

src/Symfony/Component/Lock/Store/DoctrineDbalStore.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function __construct($connOrDsn, array $options = [], float $gcProbabilit
7070
}
7171
$this->conn = DriverManager::getConnection(['url' => $connOrDsn]);
7272
} else {
73-
throw new InvalidArgumentException(sprintf('"%s" requires "Doctrine\DBAL\Connection" instance or DSN string as first argument, "%s" given.', __CLASS__, get_debug_type($connOrDsn)));
73+
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be %s or string, "%s" given.', Connection::class, __METHOD__, get_debug_type($connOrDsn)));
7474
}
7575
}
7676

@@ -211,18 +211,21 @@ private function getCurrentTimestampStatement(): string
211211
$platform = $this->conn->getDatabasePlatform();
212212
switch (true) {
213213
case $platform instanceof \Doctrine\DBAL\Platforms\MySQLPlatform:
214+
case $platform instanceof \Doctrine\DBAL\Platforms\MySQL57Platform:
214215
return 'UNIX_TIMESTAMP()';
215216

216217
case $platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform:
217218
return 'strftime(\'%s\',\'now\')';
218219

219220
case $platform instanceof \Doctrine\DBAL\Platforms\PostgreSQLPlatform:
221+
case $platform instanceof \Doctrine\DBAL\Platforms\PostgreSQL94Platform:
220222
return 'CAST(EXTRACT(epoch FROM NOW()) AS INT)';
221223

222224
case $platform instanceof \Doctrine\DBAL\Platforms\OraclePlatform:
223225
return '(SYSDATE - TO_DATE(\'19700101\',\'yyyymmdd\'))*86400 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone), 1, 3))*3600';
224226

225227
case $platform instanceof \Doctrine\DBAL\Platforms\SQLServerPlatform:
228+
case $platform instanceof \Doctrine\DBAL\Platforms\SQLServer2012Platform:
226229
return 'DATEDIFF(s, \'1970-01-01\', GETUTCDATE())';
227230

228231
default:

src/Symfony/Component/Lock/Store/PostgreSqlStore.php

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Lock\Store;
1313

1414
use Doctrine\DBAL\Connection;
15-
use Doctrine\DBAL\DriverManager;
1615
use Symfony\Component\Lock\BlockingSharedLockStoreInterface;
1716
use Symfony\Component\Lock\BlockingStoreInterface;
1817
use Symfony\Component\Lock\Exception\InvalidArgumentException;

src/Symfony/Component/Lock/Tests/Store/PostgreSqlDbalStoreTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @requires extension pdo_pgsql
2222
* @group integration
23-
* @legacy
23+
* @group legacy
2424
*/
2525
class PostgreSqlDbalStoreTest extends AbstractStoreTest
2626
{

0 commit comments

Comments
 (0)
0