Skip to content

Commit 58c7c16

Browse files
committed
[Lock] Remove support of Doctrine DBAL in PdoStore
1 parent b7faf05 commit 58c7c16

File tree

4 files changed

+5
-171
lines changed

4 files changed

+5
-171
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Remove the `NotSupportedException`. It shouldn't be thrown anymore
88
* Remove the `RetryTillSaveStore`. Logic has been moved in `Lock` and is not needed anymore
9+
* Remove support of Doctrine DBAL in `PdoStore`
910

1011
5.4
1112
---

Store/DoctrineDbalStore.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class DoctrineDbalStore implements PersistingStoreInterface
4040
use DatabaseTableTrait;
4141
use ExpiringStoreTrait;
4242

43-
private $conn;
44-
private $dsn;
43+
private Connection $conn;
4544

4645
/**
4746
* List of available options:
@@ -58,19 +57,17 @@ class DoctrineDbalStore implements PersistingStoreInterface
5857
* @throws InvalidArgumentException When namespace contains invalid characters
5958
* @throws InvalidArgumentException When the initial ttl is not valid
6059
*/
61-
public function __construct($connOrUrl, array $options = [], float $gcProbability = 0.01, int $initialTtl = 300)
60+
public function __construct(Connection|string $connOrUrl, array $options = [], float $gcProbability = 0.01, int $initialTtl = 300)
6261
{
6362
$this->init($options, $gcProbability, $initialTtl);
6463

6564
if ($connOrUrl instanceof Connection) {
6665
$this->conn = $connOrUrl;
67-
} elseif (\is_string($connOrUrl)) {
66+
} else {
6867
if (!class_exists(DriverManager::class)) {
6968
throw new InvalidArgumentException(sprintf('Failed to parse the DSN "%s". Try running "composer require doctrine/dbal".', $connOrUrl));
7069
}
7170
$this->conn = DriverManager::getConnection(['url' => $connOrUrl]);
72-
} else {
73-
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be "%s" or string, "%s" given.', Connection::class, __METHOD__, get_debug_type($connOrUrl)));
7471
}
7572
}
7673

Store/PdoStore.php

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Lock\Store;
1313

14-
use Doctrine\DBAL\Connection;
15-
use Doctrine\DBAL\Schema\Schema;
1614
use Symfony\Component\Lock\Exception\InvalidArgumentException;
1715
use Symfony\Component\Lock\Exception\InvalidTtlException;
1816
use Symfony\Component\Lock\Exception\LockConflictedException;
@@ -44,8 +42,6 @@ class PdoStore implements PersistingStoreInterface
4442
private string $password = '';
4543
private array $connectionOptions = [];
4644

47-
private $dbalStore;
48-
4945
/**
5046
* You can either pass an existing database connection as PDO instance
5147
* or a DSN string that will be used to lazy-connect to the database
@@ -68,15 +64,8 @@ class PdoStore implements PersistingStoreInterface
6864
* @throws InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
6965
* @throws InvalidArgumentException When the initial ttl is not valid
7066
*/
71-
public function __construct(\PDO|Connection|string $connOrDsn, array $options = [], float $gcProbability = 0.01, int $initialTtl = 300)
67+
public function __construct(\PDO|string $connOrDsn, array $options = [], float $gcProbability = 0.01, int $initialTtl = 300)
7268
{
73-
if ($connOrDsn instanceof Connection || (\is_string($connOrDsn) && str_contains($connOrDsn, '://'))) {
74-
trigger_deprecation('symfony/lock', '5.4', 'Usage of a DBAL Connection with "%s" is deprecated and will be removed in symfony 6.0. Use "%s" instead.', __CLASS__, DoctrineDbalStore::class);
75-
$this->dbalStore = new DoctrineDbalStore($connOrDsn, $options, $gcProbability, $initialTtl);
76-
77-
return;
78-
}
79-
8069
$this->init($options, $gcProbability, $initialTtl);
8170

8271
if ($connOrDsn instanceof \PDO) {
@@ -99,12 +88,6 @@ public function __construct(\PDO|Connection|string $connOrDsn, array $options =
9988
*/
10089
public function save(Key $key)
10190
{
102-
if (isset($this->dbalStore)) {
103-
$this->dbalStore->save($key);
104-
105-
return;
106-
}
107-
10891
$key->reduceLifetime($this->initialTtl);
10992

11093
$sql = "INSERT INTO $this->table ($this->idCol, $this->tokenCol, $this->expirationCol) VALUES (:id, :token, {$this->getCurrentTimestampStatement()} + $this->initialTtl)";
@@ -137,12 +120,6 @@ public function save(Key $key)
137120
*/
138121
public function putOffExpiration(Key $key, float $ttl)
139122
{
140-
if (isset($this->dbalStore)) {
141-
$this->dbalStore->putOffExpiration($key, $ttl);
142-
143-
return;
144-
}
145-
146123
if ($ttl < 1) {
147124
throw new InvalidTtlException(sprintf('"%s()" expects a TTL greater or equals to 1 second. Got "%s".', __METHOD__, $ttl));
148125
}
@@ -171,12 +148,6 @@ public function putOffExpiration(Key $key, float $ttl)
171148
*/
172149
public function delete(Key $key)
173150
{
174-
if (isset($this->dbalStore)) {
175-
$this->dbalStore->delete($key);
176-
177-
return;
178-
}
179-
180151
$sql = "DELETE FROM $this->table WHERE $this->idCol = :id AND $this->tokenCol = :token";
181152
$stmt = $this->getConnection()->prepare($sql);
182153

@@ -190,10 +161,6 @@ public function delete(Key $key)
190161
*/
191162
public function exists(Key $key): bool
192163
{
193-
if (isset($this->dbalStore)) {
194-
return $this->dbalStore->exists($key);
195-
}
196-
197164
$sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND $this->tokenCol = :token AND $this->expirationCol > {$this->getCurrentTimestampStatement()}";
198165
$stmt = $this->getConnection()->prepare($sql);
199166

@@ -222,12 +189,6 @@ private function getConnection(): \PDO
222189
*/
223190
public function createTable(): void
224191
{
225-
if (isset($this->dbalStore)) {
226-
$this->dbalStore->createTable();
227-
228-
return;
229-
}
230-
231192
// connect if we are not yet
232193
$conn = $this->getConnection();
233194
$driver = $this->getDriver();
@@ -255,22 +216,6 @@ public function createTable(): void
255216
$conn->exec($sql);
256217
}
257218

258-
/**
259-
* Adds the Table to the Schema if it doesn't exist.
260-
*
261-
* @deprecated since symfony/lock 5.4 use DoctrineDbalStore instead
262-
*/
263-
public function configureSchema(Schema $schema): void
264-
{
265-
if (isset($this->dbalStore)) {
266-
$this->dbalStore->configureSchema($schema);
267-
268-
return;
269-
}
270-
271-
throw new \BadMethodCallException(sprintf('"%s::%s()" is only supported when using a doctrine/dbal Connection.', __CLASS__, __METHOD__));
272-
}
273-
274219
/**
275220
* Cleans up the table by removing all expired locks.
276221
*/

Tests/Store/PdoDbalStoreTest.php

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)