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

Skip to content

Commit 93d66c1

Browse files
committed
[Lock] remove Factory for LockFactory
1 parent 06e9a91 commit 93d66c1

File tree

5 files changed

+40
-94
lines changed

5 files changed

+40
-94
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
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;
@@ -1490,12 +1489,12 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
14901489
$container->setAlias('lock.factory', new Alias('lock.'.$resourceName.'.factory', false));
14911490
$container->setAlias('lock', new Alias('lock.'.$resourceName, false));
14921491
$container->setAlias(PersistStoreInterface::class, new Alias('lock.store', false));
1493-
$container->setAlias(Factory::class, new Alias('lock.factory', false));
1492+
$container->setAlias(LockFactory::class, new Alias('lock.factory', false));
14941493
$container->setAlias(LockFactory::class, new Alias('lock.factory', false));
14951494
$container->setAlias(LockInterface::class, new Alias('lock', false));
14961495
} else {
14971496
$container->registerAliasForArgument('lock.'.$resourceName.'.store', PersistStoreInterface::class, $resourceName.'.lock.store');
1498-
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', Factory::class, $resourceName.'.lock.factory');
1497+
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName.'.lock.factory');
14991498
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName.'.lock.factory');
15001499
$container->registerAliasForArgument('lock.'.$resourceName, LockInterface::class, $resourceName.'.lock');
15011500
}

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 `PersistStoreInterface` 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: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,43 @@
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(StoreInterface $store)
31+
{
32+
$this->store = $store;
33+
34+
$this->logger = new NullLogger();
35+
}
36+
37+
/**
38+
* Creates a lock for the given resource.
39+
*
40+
* @param string $resource The resource to lock
41+
* @param float|null $ttl Maximum expected lock duration in seconds
42+
* @param bool $autoRelease Whether to automatically release the lock or not when the lock instance is destroyed
43+
*
44+
* @return Lock
45+
*/
46+
public function createLock(string $resource, ?float $ttl = 300.0, bool $autoRelease = true)
47+
{
48+
$lock = new Lock(new Key($resource), $this->store, $ttl, $autoRelease);
49+
$lock->setLogger($this->logger);
50+
51+
return $lock;
52+
}
2253
}

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

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

0 commit comments

Comments
 (0)