From dd0721a512f577faf7c05ad5b0b75ffe80f7903a Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 28 Aug 2024 08:30:27 +0200 Subject: [PATCH] add NullStore --- src/Symfony/Component/Lock/CHANGELOG.md | 5 +++ .../Component/Lock/Store/NullStore.php | 43 +++++++++++++++++++ .../Component/Lock/Store/StoreFactory.php | 3 ++ .../Lock/Tests/Store/StoreFactoryTest.php | 3 ++ 4 files changed, 54 insertions(+) create mode 100644 src/Symfony/Component/Lock/Store/NullStore.php diff --git a/src/Symfony/Component/Lock/CHANGELOG.md b/src/Symfony/Component/Lock/CHANGELOG.md index 3c7f1b834bc83..385fffbcbaeae 100644 --- a/src/Symfony/Component/Lock/CHANGELOG.md +++ b/src/Symfony/Component/Lock/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.2 +--- + + * Add `NullStore` + 7.0 --- diff --git a/src/Symfony/Component/Lock/Store/NullStore.php b/src/Symfony/Component/Lock/Store/NullStore.php new file mode 100644 index 0000000000000..10ea57b6ef359 --- /dev/null +++ b/src/Symfony/Component/Lock/Store/NullStore.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Lock\Store; + +use Symfony\Component\Lock\BlockingSharedLockStoreInterface; +use Symfony\Component\Lock\Key; + +class NullStore implements BlockingSharedLockStoreInterface +{ + public function save(Key $key): void + { + } + + public function delete(Key $key): void + { + } + + public function exists(Key $key): bool + { + return false; + } + + public function putOffExpiration(Key $key, float $ttl): void + { + } + + public function saveRead(Key $key): void + { + } + + public function waitAndSaveRead(Key $key): void + { + } +} diff --git a/src/Symfony/Component/Lock/Store/StoreFactory.php b/src/Symfony/Component/Lock/Store/StoreFactory.php index bc65182e45dde..1ce98acd0e0f1 100644 --- a/src/Symfony/Component/Lock/Store/StoreFactory.php +++ b/src/Symfony/Component/Lock/Store/StoreFactory.php @@ -106,6 +106,9 @@ public static function createStore(#[\SensitiveParameter] object|string $connect case 'in-memory' === $connection: return new InMemoryStore(); + + case 'null' === $connection: + return new NullStore(); } throw new InvalidArgumentException(\sprintf('Unsupported Connection: "%s".', $connection)); diff --git a/src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php b/src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php index 6d2319c8d760e..77df60979720b 100644 --- a/src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php +++ b/src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php @@ -20,6 +20,7 @@ use Symfony\Component\Lock\Store\FlockStore; use Symfony\Component\Lock\Store\InMemoryStore; use Symfony\Component\Lock\Store\MemcachedStore; +use Symfony\Component\Lock\Store\NullStore; use Symfony\Component\Lock\Store\PdoStore; use Symfony\Component\Lock\Store\PostgreSqlStore; use Symfony\Component\Lock\Store\RedisStore; @@ -92,5 +93,7 @@ public static function validConnections(): \Generator yield ['flock', FlockStore::class]; yield ['flock://'.sys_get_temp_dir(), FlockStore::class]; + + yield ['null', NullStore::class]; } }