8000 [Lock] Add LockFactoryInterface by Nyholm · Pull Request #39634 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Lock] Add LockFactoryInterface #39634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Lock\Lock;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Lock\LockFactoryInterface;
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\Lock\PersistingStoreInterface;
use Symfony\Component\Lock\Store\StoreFactory;
Expand Down Expand Up @@ -1705,16 +1706,22 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont

// provide alias for default resource
if ('default' === $resourceName) {
$container->setAlias('lock.store', (new Alias($storeDefinitionId, false))->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "lock.factory" instead.'));
$container->setAlias('lock.factory', new Alias('lock.'.$resourceName.'.factory', false));
$container->setAlias('lock', (new Alias('lock.'.$resourceName, false))->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "lock.factory" instead.'));
$container->setAlias(PersistingStoreInterface::class, (new Alias($storeDefinitionId, false))->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "'.LockFactory::class.'" instead.'));
$container->setAlias(LockFactory::class, new Alias('lock.factory', false));
$container->setAlias(LockInterface::class, (new Alias('lock.'.$resourceName, false))->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "'.LockFactory::class.'" instead.'));
$container->setAlias(LockFactoryInterface::class, new Alias('lock.factory', false));

$deprecationMessage = 'The "%alias_id%" alias is deprecated, use "'.LockFactoryInterface::class.'" instead.';
$container->setAlias('lock.store', (new Alias($storeDefinitionId, false))->setDeprecated('symfony/framework-bundle', '5.2', $deprecationMessage));
$container->setAlias('lock', (new Alias('lock.'.$resourceName, false))->setDeprecated('symfony/framework-bundle', '5.2', $deprecationMessage));
$container->setAlias(PersistingStoreInterface::class, (new Alias($storeDefinitionId, false))->setDeprecated('symfony/framework-bundle', '5.2', $deprecationMessage));
$container->setAlias(LockFactory::class, (new Alias('lock.factory', false))->setDeprecated('symfony/framework-bundle', '5.3', $deprecationMessage));
$container->setAlias(LockInterface::class, (new Alias('lock.'.$resourceName, false))->setDeprecated('symfony/framework-bundle', '5.2', $deprecationMessage));
} else {
$container->registerAliasForArgument($storeDefinitionId, PersistingStoreInterface::class, $resourceName.'.lock.store')->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "'.LockFactory::class.' '.$resourceName.'LockFactory" instead.');
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName.'.lock.factory');
$container->registerAliasForArgument('lock.'.$resourceName, LockInterface::class, $resourceName.'.lock')->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "'.LockFactory::class.' $'.$resourceName.'LockFactory" instead.');
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactoryInterface::class, $resourceName.'.lock.factory');

$deprecationMessage = 'The "%alias_id%" alias is deprecated, use "'.LockFactoryInterface::class.' $'.$resourceName.'LockFactory" instead.';
$container->registerAliasForArgument($storeDefinitionId, PersistingStoreInterface::class, $resourceName.'.lock.store')->setDeprecated('symfony/framework-bundle', '5.2', $deprecationMessage);
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName.'.lock.factory')->setDeprecated('symfony/framework-bundle', '5.3', $deprecationMessage);
$container->registerAliasForArgument('lock.'.$resourceName, LockInterface::class, $resourceName.'.lock')->setDeprecated('symfony/framework-bundle', '5.2', $deprecationMessage);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"symfony/dom-crawler": "<4.4",
"symfony/http-client": "<4.4",
"symfony/form": "<5.2",
"symfony/lock": "<4.4",
"symfony/lock": "<5.3",
"symfony/mailer": "<5.2",
"symfony/messenger": "<4.4",
"symfony/mime": "<4.4",
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Lock/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

5.3.0
-----

* Added `LockFactoryInterface`

5.2.0
-----

Expand Down
16 changes: 3 additions & 13 deletions src/Symfony/Component/Lock/LockFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
use Psr\Log\NullLogger;

/**
* Factory provides method to create locks.
*
* @author Jérémy Derussé <jeremy@derusse.com>
* @author Hamza Amrouche <hamza.simperfit@gmail.com>
*/
class LockFactory implements LoggerAwareInterface
class LockFactory implements LoggerAwareInterface, LockFactoryInterface
{
use LoggerAwareTrait;

Expand All @@ -35,23 +33,15 @@ public function __construct(PersistingStoreInterface $store)
}

/**
* 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
* {@inheritdoc}
*/
public function createLock(string $resource, ?float $ttl = 300.0, bool $autoRelease = true): LockInterface
{
return $this->createLockFromKey(new Key($resource), $ttl, $autoRelease);
}

/**
* Creates a lock from the given key.
*
* @param Key $key The key containing the lock's state
* @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
* {@inheritdoc}
*/
public function createLockFromKey(Key $key, ?float $ttl = 300.0, bool $autoRelease = true): LockInterface
{
Expand Down
39 changes: 39 additions & 0 deletions src/Symfony/Component/Lock/LockFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Lock;

/**
* Factory provides method to create locks.
*
* @author Jérémy Derussé <jeremy@derusse.com>
* @author Hamza Amrouche <hamza.simperfit@gmail.com>
*/
interface LockFactoryInterface
{
/**
* 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
*/
public function createLock(string $resource, ?float $ttl = 300.0, bool $autoRelease = true): LockInterface;

/**
* Creates a lock from the given key.
*
* @param Key $key The key containing the lock's state
* @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 createLockFromKey(Key $key, ?float $ttl = 300.0, bool $autoRelease = true): LockInterface;
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/RateLimiter/RateLimiterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\RateLimiter;

use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Lock\LockFactoryInterface;
use Symfony\Component\Lock\NoLock;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
Expand All @@ -33,7 +33,7 @@ final class RateLimiterFactory
private $storage;
private $lockFactory;

public function __construct(array $config, StorageInterface $storage, ?LockFactory $lockFactory = null)
public function __construct(array $config, StorageInterface $storage, ?LockFactoryInterface $lockFactory = null)
{
$this->storage = $storage;
$this->lockFactory = $lockFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/RateLimiter/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": ">=7.2.5",
"symfony/lock": "^5.2",
"symfony/lock": "^5.3",
"symfony/options-resolver": "^5.1"
},
"require-dev": {
Expand Down
0