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 1 commit
Commits
File filter

Filter by extension

Filter by extension .php  (3)


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Lock] Add LockFactoryInterface
  • Loading branch information
Nyholm committed Dec 27, 2020
commit 6786e440b0eb767fcc4af7a1fbef7daa24ea8bbe
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
18 changes: 1 addition & 17 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 LoggerAwareInter 10000 face, LockFactoryInterface
{
use LoggerAwareTrait;

Expand All @@ -34,25 +32,11 @@ public function __construct(PersistingStoreInterface $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
*/
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
*/
public function createLockFromKey(Key $key, ?float $ttl = 300.0, bool $autoRelease = true): LockInterface
{
$lock = new Lock($key, $this->store, $ttl, $autoRelease);
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