Skip to content

Commit a8f7383

Browse files
committed
Use a WeakMap as store registry
1 parent 07212a5 commit a8f7383

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

Store/DoctrineDbalPostgreSqlStore.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
class DoctrineDbalPostgreSqlStore implements BlockingSharedLockStoreInterface, BlockingStoreInterface
3434
{
3535
private Connection $conn;
36-
private static array $storeRegistry = [];
3736

3837
/**
3938
* You can either pass an existing database connection a Doctrine DBAL Connection
@@ -278,8 +277,8 @@ private function filterDsn(#[\SensitiveParameter] string $dsn): string
278277

279278
private function getInternalStore(): SharedLockStoreInterface
280279
{
281-
$namespace = spl_object_hash($this->conn);
280+
static $storeRegistry = new \WeakMap();
282281

283-
return self::$storeRegistry[$namespace] ??= new InMemoryStore();
282+
return $storeRegistry[$this->conn] ??= new InMemoryStore();
284283
}
285284
}

Store/PostgreSqlStore.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class PostgreSqlStore implements BlockingSharedLockStoreInterface, BlockingStore
3131
private ?string $username = null;
3232
private ?string $password = null;
3333
private array $connectionOptions = [];
34-
private static array $storeRegistry = [];
3534

3635
/**
3736
* You can either pass an existing database connection as PDO instance or
@@ -283,8 +282,8 @@ private function checkDriver(): void
283282

284283
private function getInternalStore(): SharedLockStoreInterface
285284
{
286-
$namespace = spl_object_hash($this->getConnection());
285+
static $storeRegistry = new \WeakMap();
287286

288-
return self::$storeRegistry[$namespace] ??= new InMemoryStore();
287+
return $storeRegistry[$this->getConnection()] ??= new InMemoryStore();
289288
}
290289
}

0 commit comments

Comments
 (0)