diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 1f1de19b72a63..2baff411fd2f9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -68,14 +68,12 @@ use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface; use Symfony\Component\HttpKernel\DependencyInjection\Extension; -use Symfony\Component\Lock\Factory; use Symfony\Component\Lock\Lock; use Symfony\Component\Lock\LockFactory; use Symfony\Component\Lock\LockInterface; use Symfony\Component\Lock\PersistingStoreInterface; use Symfony\Component\Lock\Store\FlockStore; use Symfony\Component\Lock\Store\StoreFactory; -use Symfony\Component\Lock\StoreInterface; use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesTransportFactory; use Symfony\Component\Mailer\Bridge\Google\Transport\GmailTransportFactory; use Symfony\Component\Mailer\Bridge\Mailchimp\Transport\MandrillTransportFactory; @@ -1499,15 +1497,11 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont $container->setAlias('lock.store', new Alias('lock.'.$resourceName.'.store', false)); $container->setAlias('lock.factory', new Alias('lock.'.$resourceName.'.factory', false)); $container->setAlias('lock', new Alias('lock.'.$resourceName, false)); - $container->setAlias(StoreInterface::class, new Alias('lock.store', false)); $container->setAlias(PersistingStoreInterface::class, new Alias('lock.store', false)); - $container->setAlias(Factory::class, new Alias('lock.factory', false)); $container->setAlias(LockFactory::class, new Alias('lock.factory', false)); $container->setAlias(LockInterface::class, new Alias('lock', false)); } else { - $container->registerAliasForArgument('lock.'.$resourceName.'.store', StoreInterface::class, $resourceName.'.lock.store'); $container->registerAliasForArgument('lock.'.$resourceName.'.store', PersistingStoreInterface::class, $resourceName.'.lock.store'); - $container->registerAliasForArgument('lock.'.$resourceName.'.factory', Factory::class, $resourceName.'.lock.factory'); $container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName.'.lock.factory'); $container->registerAliasForArgument('lock.'.$resourceName, LockInterface::class, $resourceName.'.lock'); } diff --git a/src/Symfony/Component/Lock/CHANGELOG.md b/src/Symfony/Component/Lock/CHANGELOG.md index 0189982baa21d..e0e6997033a12 100644 --- a/src/Symfony/Component/Lock/CHANGELOG.md +++ b/src/Symfony/Component/Lock/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +5.0.0 +----- + +* `Factory` has been removed, use `LockFactory` instead. +* `StoreInterface` has been removed, use `BlockingStoreInterface` and `PersistingStoreInterface` instead. + 4.4.0 ----- diff --git a/src/Symfony/Component/Lock/Factory.php b/src/Symfony/Component/Lock/Factory.php deleted file mode 100644 index 2bc7d9304bd7f..0000000000000 --- a/src/Symfony/Component/Lock/Factory.php +++ /dev/null @@ -1,54 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Lock; - -use Psr\Log\LoggerAwareInterface; -use Psr\Log\LoggerAwareTrait; -use Psr\Log\NullLogger; - -/** - * Factory provides method to create locks. - * - * @author Jérémy Derussé - * - * @deprecated "Symfony\Component\Lock\Factory" is deprecated since Symfony 4.4 and will be removed in 5.0 use "Symfony\Component\Lock\LockFactory" instead - */ -class Factory implements LoggerAwareInterface -{ - use LoggerAwareTrait; - - private $store; - - public function __construct(StoreInterface $store) - { - $this->store = $store; - - $this->logger = new NullLogger(); - } - - /** - * Creates a lock for the given resource. - * - * @param string $resource The resource to lock - * @param float|null $ttl Maximum expected lock duration in seconds - * @param bool $autoRelease Whether to automatically release the lock or not when the lock instance is destroyed - * - * @return Lock - */ - public function createLock($resource, $ttl = 300.0, $autoRelease = true) - { - $lock = new Lock(new Key($resource), $this->store, $ttl, $autoRelease); - $lock->setLogger($this->logger); - - return $lock; - } -} diff --git a/src/Symfony/Component/Lock/Lock.php b/src/Symfony/Component/Lock/Lock.php index 4323301c69209..f7da528d1c777 100644 --- a/src/Symfony/Component/Lock/Lock.php +++ b/src/Symfony/Component/Lock/Lock.php @@ -71,7 +71,7 @@ public function acquire($blocking = false): ?bool { try { if ($blocking) { - if (!$this->store instanceof StoreInterface && !$this->store instanceof BlockingStoreInterface) { + if (!$this->store instanceof BlockingStoreInterface) { throw new NotSupportedException(sprintf('The store "%s" does not support blocking locks.', \get_class($this->store))); } $this->store->waitAndSave($this->key); diff --git a/src/Symfony/Component/Lock/LockFactory.php b/src/Symfony/Component/Lock/LockFactory.php index 2de93ce232812..9157f90a2357e 100644 --- a/src/Symfony/Component/Lock/LockFactory.php +++ b/src/Symfony/Component/Lock/LockFactory.php @@ -11,14 +11,29 @@ namespace Symfony\Component\Lock; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; +use Psr\Log\NullLogger; + /** * Factory provides method to create locks. * * @author Jérémy Derussé * @author Hamza Amrouche */ -class LockFactory extends Factory +class LockFactory implements LoggerAwareInterface { + use LoggerAwareTrait; + + private $store; + + public function __construct(PersistingStoreInterface $store) + { + $this->store = $store; + + $this->logger = new NullLogger(); + } + /** * Creates a lock for the given resource. * @@ -26,8 +41,11 @@ class LockFactory extends Factory * @param float|null $ttl Maximum expected lock duration in seconds * @param bool $autoRelease Whether to automatically release the lock or not when the lock instance is destroyed */ - public function createLock($resource, $ttl = 300.0, $autoRelease = true): Lock + public function createLock(string $resource, ?float $ttl = 300.0, bool $autoRelease = true): Lock { - return parent::createLock($resource, $ttl, $autoRelease); + $lock = new Lock(new Key($resource), $this->store, $ttl, $autoRelease); + $lock->setLogger($this->logger); + + return $lock; } } diff --git a/src/Symfony/Component/Lock/Store/CombinedStore.php b/src/Symfony/Component/Lock/Store/CombinedStore.php index bb66fcd727545..49d40566a4859 100644 --- a/src/Symfony/Component/Lock/Store/CombinedStore.php +++ b/src/Symfony/Component/Lock/Store/CombinedStore.php @@ -19,7 +19,6 @@ use Symfony\Component\Lock\Exception\NotSupportedException; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\PersistingStoreInterface; -use Symfony\Component\Lock\StoreInterface; use Symfony\Component\Lock\Strategy\StrategyInterface; /** @@ -27,7 +26,7 @@ * * @author Jérémy Derussé */ -class CombinedStore implements StoreInterface, LoggerAwareInterface +class CombinedStore implements PersistingStoreInterface, LoggerAwareInterface { use LoggerAwareTrait; use ExpiringStoreTrait; diff --git a/src/Symfony/Component/Lock/Store/FlockStore.php b/src/Symfony/Component/Lock/Store/FlockStore.php index f566a0d205210..b2107663a596f 100644 --- a/src/Symfony/Component/Lock/Store/FlockStore.php +++ b/src/Symfony/Component/Lock/Store/FlockStore.php @@ -16,7 +16,7 @@ use Symfony\Component\Lock\Exception\LockConflictedException; use Symfony\Component\Lock\Exception\LockStorageException; use Symfony\Component\Lock\Key; -use Symfony\Component\Lock\StoreInterface; +use Symfony\Component\Lock\PersistingStoreInterface; /** * FlockStore is a PersistingStoreInterface implementation using the FileSystem flock. @@ -28,7 +28,7 @@ * @author Romain Neutron * @author Nicolas Grekas */ -class FlockStore implements StoreInterface, BlockingStoreInterface +class FlockStore implements PersistingStoreInterface, BlockingStoreInterface { private $lockPath; diff --git a/src/Symfony/Component/Lock/Store/MemcachedStore.php b/src/Symfony/Component/Lock/Store/MemcachedStore.php index 5e99b39814990..d16ca154509ec 100644 --- a/src/Symfony/Component/Lock/Store/MemcachedStore.php +++ b/src/Symfony/Component/Lock/Store/MemcachedStore.php @@ -15,14 +15,14 @@ use Symfony\Component\Lock\Exception\InvalidTtlException; use Symfony\Component\Lock\Exception\LockConflictedException; use Symfony\Component\Lock\Key; -use Symfony\Component\Lock\StoreInterface; +use Symfony\Component\Lock\PersistingStoreInterface; /** * MemcachedStore is a PersistingStoreInterface implementation using Memcached as store engine. * * @author Jérémy Derussé */ -class MemcachedStore implements StoreInterface +class MemcachedStore implements PersistingStoreInterface { use ExpiringStoreTrait; diff --git a/src/Symfony/Component/Lock/Store/PdoStore.php b/src/Symfony/Component/Lock/Store/PdoStore.php index 4c8d9e461d6e5..a35e142061c3f 100644 --- a/src/Symfony/Component/Lock/Store/PdoStore.php +++ b/src/Symfony/Component/Lock/Store/PdoStore.php @@ -19,7 +19,7 @@ use Symfony\Component\Lock\Exception\LockConflictedException; use Symfony\Component\Lock\Exception\NotSupportedException; use Symfony\Component\Lock\Key; -use Symfony\Component\Lock\StoreInterface; +use Symfony\Component\Lock\PersistingStoreInterface; /** * PdoStore is a PersistingStoreInterface implementation using a PDO connection. @@ -34,7 +34,7 @@ * * @author Jérémy Derussé */ -class PdoStore implements StoreInterface +class PdoStore implements PersistingStoreInterface { use ExpiringStoreTrait; diff --git a/src/Symfony/Component/Lock/Store/RedisStore.php b/src/Symfony/Component/Lock/Store/RedisStore.php index a20fb89a013b8..c1aecbfcd2dc6 100644 --- a/src/Symfony/Component/Lock/Store/RedisStore.php +++ b/src/Symfony/Component/Lock/Store/RedisStore.php @@ -17,14 +17,14 @@ use Symfony\Component\Lock\Exception\InvalidTtlException; use Symfony\Component\Lock\Exception\LockConflictedException; use Symfony\Component\Lock\Key; -use Symfony\Component\Lock\StoreInterface; +use Symfony\Component\Lock\PersistingStoreInterface; /** * RedisStore is a PersistingStoreInterface implementation using Redis as store engine. * * @author Jérémy Derussé */ -class RedisStore implements StoreInterface +class RedisStore implements PersistingStoreInterface { use ExpiringStoreTrait; diff --git a/src/Symfony/Component/Lock/Store/RetryTillSaveStore.php b/src/Symfony/Component/Lock/Store/RetryTillSaveStore.php index 9a412810c2489..18890536f0576 100644 --- a/src/Symfony/Component/Lock/Store/RetryTillSaveStore.php +++ b/src/Symfony/Component/Lock/Store/RetryTillSaveStore.php @@ -18,7 +18,6 @@ use Symfony\Component\Lock\Exception\LockConflictedException; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\PersistingStoreInterface; -use Symfony\Component\Lock\StoreInterface; /** * RetryTillSaveStore is a PersistingStoreInterface implementation which decorate a non blocking PersistingStoreInterface to provide a @@ -26,7 +25,7 @@ * * @author Jérémy Derussé */ -class RetryTillSaveStore implements BlockingStoreInterface, StoreInterface, LoggerAwareInterface +class RetryTillSaveStore implements BlockingStoreInterface, LoggerAwareInterface { use LoggerAwareTrait; diff --git a/src/Symfony/Component/Lock/Store/SemaphoreStore.php b/src/Symfony/Component/Lock/Store/SemaphoreStore.php index d9fefeea7a5e5..829da3bfc661f 100644 --- a/src/Symfony/Component/Lock/Store/SemaphoreStore.php +++ b/src/Symfony/Component/Lock/Store/SemaphoreStore.php @@ -15,14 +15,13 @@ use Symfony\Component\Lock\Exception\InvalidArgumentException; use Symfony\Component\Lock\Exception\LockConflictedException; use Symfony\Component\Lock\Key; -use Symfony\Component\Lock\StoreInterface; /** * SemaphoreStore is a PersistingStoreInterface implementation using Semaphore as store engine. * * @author Jérémy Derussé */ -class SemaphoreStore implements StoreInterface, BlockingStoreInterface +class SemaphoreStore implements BlockingStoreInterface { /** * Returns whether or not the store is supported. diff --git a/src/Symfony/Component/Lock/Store/ZookeeperStore.php b/src/Symfony/Component/Lock/Store/ZookeeperStore.php index 112e1e8d752e7..681416c905afc 100644 --- a/src/Symfony/Component/Lock/Store/ZookeeperStore.php +++ b/src/Symfony/Component/Lock/Store/ZookeeperStore.php @@ -16,14 +16,14 @@ use Symfony\Component\Lock\Exception\LockReleasingException; use Symfony\Component\Lock\Exception\NotSupportedException; use Symfony\Component\Lock\Key; -use Symfony\Component\Lock\StoreInterface; +use Symfony\Component\Lock\PersistingStoreInterface; /** * ZookeeperStore is a PersistingStoreInterface implementation using Zookeeper as store engine. * * @author Ganesh Chandrasekaran */ -class ZookeeperStore implements StoreInterface +class ZookeeperStore implements PersistingStoreInterface { use ExpiringStoreTrait; diff --git a/src/Symfony/Component/Lock/StoreInterface.php b/src/Symfony/Component/Lock/StoreInterface.php deleted file mode 100644 index 5bd60cd5ceb0e..0000000000000 --- a/src/Symfony/Component/Lock/StoreInterface.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Lock; - -use Symfony\Component\Lock\Exception\LockConflictedException; -use Symfony\Component\Lock\Exception\NotSupportedException; - -/** - * StoreInterface defines an interface to manipulate a lock store. - * - * @author Jérémy Derussé - * - * @deprecated since Symfony 4.4, use PersistingStoreInterface and BlockingStoreInterface instead - */ -interface StoreInterface extends PersistingStoreInterface -{ - /** - * Waits until a key becomes free, then stores the resource. - * - * If the store does not support this feature it should throw a NotSupportedException. - * - * @throws LockConflictedException - * @throws NotSupportedException - */ - public function waitAndSave(Key $key); -} diff --git a/src/Symfony/Component/Lock/Tests/FactoryTest.php b/src/Symfony/Component/Lock/Tests/FactoryTest.php deleted file mode 100644 index d67949098c7a4..0000000000000 --- a/src/Symfony/Component/Lock/Tests/FactoryTest.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Lock\Tests; - -use PHPUnit\Framework\TestCase; -use Psr\Log\LoggerInterface; -use Symfony\Component\Lock\Factory; -use Symfony\Component\Lock\LockInterface; -use Symfony\Component\Lock\StoreInterface; - -/** - * @author Jérémy Derussé - */ -class FactoryTest extends TestCase -{ - public function testCreateLock() - { - $store = $this->getMockBuilder(StoreInterface::class)->getMock(); - $logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); - $factory = new Factory($store); - $factory->setLogger($logger); - - $lock = $factory->createLock('foo'); - - $this->assertInstanceOf(LockInterface::class, $lock); - } -} diff --git a/src/Symfony/Component/Lock/Tests/LockFactoryTest.php b/src/Symfony/Component/Lock/Tests/LockFactoryTest.php index 0ec4fd3976a4f..376bd692a5d00 100644 --- a/src/Symfony/Component/Lock/Tests/LockFactoryTest.php +++ b/src/Symfony/Component/Lock/Tests/LockFactoryTest.php @@ -15,7 +15,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\Lock\LockFactory; use Symfony\Component\Lock\LockInterface; -use Symfony\Component\Lock\StoreInterface; +use Symfony\Component\Lock\PersistingStoreInterface; /** * @author Jérémy Derussé @@ -24,7 +24,7 @@ class LockFactoryTest extends TestCase { public function testCreateLock() { - $store = $this->getMockBuilder(StoreInterface::class)->getMock(); + $store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock(); $logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $factory = new LockFactory($store); $factory->setLogger($logger); diff --git a/src/Symfony/Component/Lock/Tests/LockTest.php b/src/Symfony/Component/Lock/Tests/LockTest.php index aae7a7671d480..f5c2b0cc5c147 100644 --- a/src/Symfony/Component/Lock/Tests/LockTest.php +++ b/src/Symfony/Component/Lock/Tests/LockTest.php @@ -18,7 +18,6 @@ use Symfony\Component\Lock\Key; use Symfony\Component\Lock\Lock; use Symfony\Component\Lock\PersistingStoreInterface; -use Symfony\Component\Lock\StoreInterface; /** * @author Jérémy Derussé @@ -51,22 +50,6 @@ public function testAcquireNoBlockingStoreInterface() $this->assertTrue($lock->acquire(false)); } - /** - * @group legacy - */ - public function testPassingOldStoreInterface() - { - $key = new Key(uniqid(__METHOD__, true)); - $store = $this->getMockBuilder(StoreInterface::class)->getMock(); - $lock = new Lock($key, $store); - - $store - ->expects($this->once()) - ->method('save'); - - $this->assertTrue($lock->acquire(false)); - } - public function testAcquireReturnsFalse() { $key = new Key(uniqid(__METHOD__, true));