8000 [Lock] Remove support of Doctrine DBAL in PdoStore · symfony/symfony@2045c2c · GitHub
[go: up one dir, main page]

Skip to content

Commit 2045c2c

Browse files
committed
[Lock] Remove support of Doctrine DBAL in PdoStore
1 parent d8699ef commit 2045c2c

File tree

4 files changed

+4
-168
lines changed

4 files changed

+4
-168
lines changed

src/Symfony/Component/Lock/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
---

src/Symfony/Component/Lock/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

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

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ class PdoStore implements PersistingStoreInterface
4444
private string $password = '';
4545
private array $connectionOptions = [];
4646

47-
private $dbalStore;
48-
4947
/**
5048
* You can either pass an existing database connection as PDO instance
5149
* or a DSN string that will be used to lazy-connect to the database
@@ -70,13 +68,6 @@ class PdoStore implements PersistingStoreInterface
7068
*/
7169
public function __construct(\PDO|Connection|string $connOrDsn, array $options = [], float $gcProbability = 0.01, int $initialTtl = 300)
7270
{
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-
8071
$this->init($options, $gcProbability, $initialTtl);
8172

8273
if ($connOrDsn instanceof \PDO) {
@@ -99,12 +90,6 @@ public function __construct(\PDO|Connection|string $connOrDsn, array $options =
9990
*/
10091
public function save(Key $key)
10192
{
102-
if (isset($this->dbalStore)) {
103-
$this->dbalStore->save($key);
104-
105-
return;
106-
}
107-
10893
$key->reduceLifetime($this->initialTtl);
10994

11095
$sql = "INSERT INTO $this->table ($this->idCol, $this->tokenCol, $this->expirationCol) VALUES (:id, :token, {$this->getCurrentTimestampStatement()} + $this->initialTtl)";
@@ -137,12 +122,6 @@ public function save(Key $key)
137122
*/
138123
public function putOffExpiration(Key $key, float $ttl)
139124
{
140-
if (isset($this->dbalStore)) {
141-
$this->dbalStore->putOffExpiration($key, $ttl);
142-
143-
return;
144-
}
145-
146125
if ($ttl < 1) {
147126
throw new InvalidTtlException(sprintf('"%s()" expects a TTL greater or equals to 1 second. Got "%s".', __METHOD__, $ttl));
148127
}
@@ -171,12 +150,6 @@ public function putOffExpiration(Key $key, float $ttl)
171150
*/
172151
public function delete(Key $key)
173152
{
174-
if (isset($this->dbalStore)) {
175-
$this->dbalStore->delete($key);
176-
177-
return;
178-
}
179-
180153
$sql = "DELETE FROM $this->table WHERE $this->idCol = :id AND $this->tokenCol = :token";
181154
$stmt = $this->getConnection()->prepare($sql);
182155

@@ -190,10 +163,6 @@ public function delete(Key $key)
190163
*/
191164
public function exists(Key $key): bool
192165
{
193-
if (isset($this->dbalStore)) {
194-
return $this->dbalStore->exists($key);
195-
}
196-
197166
$sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND $this->tokenCol = :token AND $this->expirationCol > {$this->getCurrentTimestampStatement()}";
198167
$stmt = $this->getConnection()->prepare($sql);
199168

@@ -222,12 +191,6 @@ private function getConnection(): \PDO
222191
*/
223192
public function createTable(): void
224193
{
225-
if (isset($this->dbalStore)) {
226-
$this->dbalStore->createTable();
227-
228-
return;
229-
}
230-
231194
// connect if we are not yet
232195
$conn = $this->getConnection();
233196
$driver = $this->getDriver();
@@ -255,22 +218,6 @@ public function createTable(): void
255218
$conn->exec($sql);
256219
}
257220

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-
274221
/**
275222
* Cleans up the table by removing all expired locks.
276223
*/

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

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

0 commit comments

Comments
 (0)
0