Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c6ebc6

Browse files
committed
[Lock] remove Factory for LockFactory
1 parent 8bfdd48 commit 1c6ebc6

15 files changed

+43
-134
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@
6868
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
6969
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
7070
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
71-
use Symfony\Component\Lock\Factory;
7271
use Symfony\Component\Lock\Lock;
7372
use Symfony\Component\Lock\LockFactory;
7473
use Symfony\Component\Lock\LockInterface;
7574
use Symfony\Component\Lock\PersistingStoreInterface;
7675
use Symfony\Component\Lock\Store\FlockStore;
7776
use Symfony\Component\Lock\Store\StoreFactory;
78-
use Symfony\Component\Lock\StoreInterface;
7977
use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesTransportFactory;
8078
use Symfony\Component\Mailer\Bridge\Google\Transport\GmailTransportFactory;
8179
use Symfony\Component\Mailer\Bridge\Mailchimp\Transport\MandrillTransportFactory;
@@ -1499,15 +1497,11 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
14991497
$container->setAlias('lock.store', new Alias('lock.'.$resourceName.'.store', false));
15001498
$container->setAlias('lock.factory', new Alias('lock.'.$resourceName.'.factory', false));
15011499
$container->setAlias('lock', new Alias('lock.'.$resourceName, false));
1502-
$container->setAlias(StoreInterface::class, new Alias('lock.store', false));
15031500
$container->setAlias(PersistingStoreInterface::class, new Alias('lock.store', false));
1504-
$container->setAlias(Factory::class, new Alias('lock.factory', false));
15051501
$container->setAlias(LockFactory::class, new Alias('lock.factory', false));
15061502
$container->setAlias(LockInterface::class, new Alias('lock', false));
15071503
} else {
1508-
$container->registerAliasForArgument('lock.'.$resourceName.'.store', StoreInterface::class, $resourceName.'.lock.store');
15091504
$container->registerAliasForArgument('lock.'.$resourceName.'.store', PersistingStoreInterface::class, $resourceName.'.lock.store');
1510-
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', Factory::class, $resourceName.'.lock.factory');
15111505
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName.'.lock.factory');
15121506
$container->registerAliasForArgument('lock.'.$resourceName, LockInterface::class, $resourceName.'.lock');
15131507
}

src/Symfony/Component/Lock/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
5.0.0
5+
-----
6+
7+
* `Factory` has been removed, use `LockFactory` instead.
8+
* `StoreInterface` has been removed, use `BlockingStoreInterface` and `PersistingStoreInterface` instead.
9+
410
4.4.0
511
-----
612

src/Symfony/Component/Lock/Factory.php

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

src/Symfony/Component/Lock/LockFactory.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,41 @@
1111

1212
namespace Symfony\Component\Lock;
1313

14+
use Psr\Log\LoggerAwareInterface;
15+
use Psr\Log\LoggerAwareTrait;
16+
use Psr\Log\NullLogger;
17+
1418
/**
1519
* Factory provides method to create locks.
1620
*
1721
* @author Jérémy Derussé <[email protected]>
1822
* @author Hamza Amrouche <[email protected]>
1923
*/
20-
class LockFactory extends Factory
24+
class LockFactory implements LoggerAwareInterface
2125
{
26+
use LoggerAwareTrait;
27+
28+
private $store;
29+
30+
public function __construct(PersistingStoreInterface $store)
31+
{
32+
$this->store = $store;
33+
34+
$this->logger = new NullLogger();
35+
}
36+
2237
/**
2338
* Creates a lock for the given resource.
2439
*
2540
* @param string $resource The resource to lock
2641
* @param float|null $ttl Maximum expected lock duration in seconds
2742
* @param bool $autoRelease Whether to automatically release the lock or not when the lock instance is destroyed
2843
*/
29-
public function createLock($resource, $ttl = 300.0, $autoRelease = true): Lock
44+
public function createLock(string $resource, ?float $ttl = 300.0, bool $autoRelease = true): Lock
3045
{
31-
return parent::createLock($resource, $ttl, $autoRelease);
46+
$lock = new Lock(new Key($resource), $this->store, $ttl, $autoRelease);
47+
$lock->setLogger($this->logger);
48+
49+
return $lock;
3250
}
3351
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919
use Symfony\Component\Lock\Exception\NotSupportedException;
2020
use Symfony\Component\Lock\Key;
2121
use Symfony\Component\Lock\PersistingStoreInterface;
22-
use Symfony\Component\Lock\StoreInterface;
2322
use Symfony\Component\Lock\Strategy\StrategyInterface;
2423

2524
/**
2625
* CombinedStore is a PersistingStoreInterface implementation able to manage and synchronize several StoreInterfaces.
2726
*
2827
* @author Jérémy Derussé <[email protected]>
2928
*/
30-
class CombinedStore implements StoreInterface, LoggerAwareInterface
29+
class CombinedStore implements PersistingStoreInterface, LoggerAwareInterface
3130
{
3231
use LoggerAwareTrait;
3332
use ExpiringStoreTrait;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\Lock\Exception\LockConflictedException;
1717
use Symfony\Component\Lock\Exception\LockStorageException;
1818
use Symfony\Component\Lock\Key;
19-
use Symfony\Component\Lock\StoreInterface;
19+
use Symfony\Component\Lock\PersistingStoreInterface;
2020

2121
/**
2222
* FlockStore is a PersistingStoreInterface implementation using the FileSystem flock.
@@ -28,7 +28,7 @@
2828
* @author Romain Neutron <[email protected]>
2929
* @author Nicolas Grekas <[email protected]>
3030
*/
31-
class FlockStore implements StoreInterface, BlockingStoreInterface
31+
class FlockStore implements PersistingStoreInterface, BlockingStoreInterface
3232
{
3333
private $lockPath;
3434

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
use Symfony\Component\Lock\Exception\InvalidTtlException;
1616
use Symfony\Component\Lock\Exception\LockConflictedException;
1717
use Symfony\Component\Lock\Key;
18-
use Symfony\Component\Lock\StoreInterface;
18+
use Symfony\Component\Lock\PersistingStoreInterface;
1919

2020
/**
2121
* MemcachedStore is a PersistingStoreInterface implementation using Memcached as store engine.
2222
*
2323
* @author Jérémy Derussé <[email protected]>
2424
*/
25-
class MemcachedStore implements StoreInterface
25+
class MemcachedStore implements PersistingStoreInterface
2626
{
2727
use ExpiringStoreTrait;
2828

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Symfony\Component\Lock\Exception\LockConflictedException;
2020
use Symfony\Component\Lock\Exception\NotSupportedException;
2121
use Symfony\Component\Lock\Key;
22-
use Symfony\Component\Lock\StoreInterface;
22+
use Symfony\Component\Lock\PersistingStoreInterface;
2323

2424
/**
2525
* PdoStore is a PersistingStoreInterface implementation using a PDO connection.
@@ -34,7 +34,7 @@
3434
*
3535
* @author Jérémy Derussé <[email protected]>
3636
*/
37-
class PdoStore implements StoreInterface
37+
class PdoStore implements PersistingStoreInterface
3838
{
3939
use ExpiringStoreTrait;
4040

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
use Symfony\Component\Lock\Exception\InvalidTtlException;
1818
use Symfony\Component\Lock\Exception\LockConflictedException;
1919
use Symfony\Component\Lock\Key;
20-
use Symfony\Component\Lock\StoreInterface;
20+
use Symfony\Component\Lock\PersistingStoreInterface;
2121

2222
/**
2323
* RedisStore is a PersistingStoreInterface implementation using Redis as store engine.
2424
*
2525
* @author Jérémy Derussé <[email protected]>
2626
*/
27-
class RedisStore implements StoreInterface
27+
class RedisStore implements PersistingStoreInterface
2828
{
2929
use ExpiringStoreTrait;
3030

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
use Symfony\Component\Lock\Exception\LockConflictedException;
1919
use Symfony\Component\Lock\Key;
2020
use Symfony\Component\Lock\PersistingStoreInterface;
21-
use Symfony\Component\Lock\StoreInterface;
2221

2322
/**
2423
* RetryTillSaveStore is a PersistingStoreInterface implementation which decorate a non blocking PersistingStoreInterface to provide a
2524
* blocking storage.
2625
*
2726
* @author Jérémy Derussé <[email protected]>
2827
*/
29-
class RetryTillSaveStore implements BlockingStoreInterface, StoreInterface, LoggerAwareInterface
28+
class RetryTillSaveStore implements BlockingStoreInterface, LoggerAwareInterface
3029
{
3130
use LoggerAwareTrait;
3231

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
use Symfony\Component\Lock\Exception\InvalidArgumentException;
1616
use Symfony\Component\Lock\Exception\LockConflictedException;
1717
use Symfony\Component\Lock\Key;
18-
use Symfony\Component\Lock\StoreInterface;
18+
use Symfony\Component\Lock\PersistingStoreInterface;
1919

2020
/**
2121
* SemaphoreStore is a PersistingStoreInterface implementation using Semaphore as store engine.
2222
*
2323
* @author Jérémy Derussé <[email protected]>
2424
*/
25-
class SemaphoreStore implements StoreInterface, BlockingStoreInterface
25+
class SemaphoreStore implements BlockingStoreInterface
2626
{
2727
/**
2828
* Returns whether or not the store is supported.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
use Symfony\Component\Lock\Exception\LockReleasingException;
1717
use Symfony\Component\Lock\Exception\NotSupportedException;
1818
use Symfony\Component\Lock\Key;
19-
use Symfony\Component\Lock\StoreInterface;
19+
use Symfony\Component\Lock\PersistingStoreInterface;
2020

2121
/**
2222
* ZookeeperStore is a PersistingStoreInterface implementation using Zookeeper as store engine.
2323
*
2424
* @author Ganesh Chandrasekaran <[email protected]>
2525
*/
26-
class ZookeeperStore implements StoreInterface
26+
class ZookeeperStore implements PersistingStoreInterface
2727
{
2828
use ExpiringStoreTrait;
2929

src/Symfony/Component/Lock/Tests/FactoryTest.php

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

src/Symfony/Component/Lock/Tests/LockFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Psr\Log\LoggerInterface;
1616
use Symfony\Component\Lock\LockFactory;
1717
use Symfony\Component\Lock\LockInterface;
18-
use Symfony\Component\Lock\PersistStoreInterface;
18+
use Symfony\Component\Lock\PersistingStoreInterface;
1919

2020
/**
2121
* @author Jérémy Derussé <[email protected]>
@@ -24,7 +24,7 @@ class LockFactoryTest extends TestCase
2424
{
2525
public function testCreateLock()
2626
{
27-
$store = $this->getMockBuilder(PersistStoreInterface::class)->getMock();
27+
$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
2828
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
2929
$factory = new LockFactory($store);
3030
$factory->setLogger($logger);

src/Symfony/Component/Lock/Tests/LockTest.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\Lock\Key;
1919
use Symfony\Component\Lock\Lock;
2020
use Symfony\Component\Lock\PersistingStoreInterface;
21-
use Symfony\Component\Lock\StoreInterface;
2221

2322
/**
2423
* @author Jérémy Derussé <[email protected]>
@@ -51,22 +50,6 @@ public function testAcquireNoBlockingStoreInterface()
5150
$this->assertTrue($lock->acquire(false));
5251
}
5352

54-
/**
55-
* @group legacy
56-
*/
57-
public function testPassingOldStoreInterface()
58-
{
59-
$key = new Key(uniqid(__METHOD__, true));
60-
$store = $this->getMockBuilder(StoreInterface::class)->getMock();
61-
$lock = new Lock($key, $store);
62-
63-
$store
64-
->expects($this->once())
65-
->method('save');
66-
67-
$this->assertTrue($lock->acquire(false));
68-
}
69-
7053
public function testAcquireReturnsFalse()
7154
{
7255
$key = new Key(uniqid(__METHOD__, true));

0 commit comments

Comments
 (0)