mauretto78 / locker-manager
Locker Manager
v1.0.6
2017-11-16 14:06 UTC
Requires
- php: ^5.6 || ^7.0
- cocur/slugify: ^2.3
- ramsey/uuid: ^3.7
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.3
- phpunit/phpunit: ~5.7
- predis/predis: ^1.1
- satooshi/php-coveralls: dev-master
Suggests
- ext-curl: Allows access to Webdis when paired with phpiredis
- predis/predis: Flexible and feature-complete Redis client.
This package is not auto-updated.
Last update: 2025-03-30 06:24:52 UTC
README
This library is suitable for you if you need to simple lock system.
Installation
composer require mauretto78/locker-manager
Basic Usage
Instantiate LockerManager
To instantiate the LockerManager you must inject an implementation of LockerStoreInterface
. You can use:
FLockerStore
PdoLockerStore
RedisLockerStore
Take a look:
use LockerManager\Application\LockerManager; use LockerManager\Infrastructure\FLockerStore; use LockerManager\Infrastructure\PdoLockerStore; use LockerManager\Infrastructure\RedisLockerStore; use Predis\Client; // Filesystem implementation $fLockerStore = new FLockerStore('var/lock/'); $lockerManager = new LockerManager($fLockerStore);
// .. // PDO implementation $pdoLockerStore = new PdoLockerStore(new \PDO($config)); $lockerManager = new LockerManager($pdoLockerStore);
// .. // Redis implementation uses PRedis Client $redisLockerStore = new RedisLockerStore(new Client($config)); $lockerManager = new LockerManager($redisLockerStore);
Acquire, get, delete and update a lock
This library uses Slugify to save lock keys.
Once a key is saved, this will be unique. An ExistingKeyException
will be thrown if you try to save a lock with the same key.
Please consider this example:
// .. // acquire $lock = new Lock( 'Sample Lock', [ 'name' => 'John Doe', 'email' => 'john.doe@gmail.com', 'age' => 33, ] ); $lockerManager->acquire($lock); // get a lock $sampleLock = $lockerManager->get('Sample Lock'); // delete a lock $lockerManager->delete('Sample Lock'); // update a lock $lockerManager->update( 'Sample Lock', [ 'name' => 'Maria Dante', 'email' => 'maria.dante@gmail.com', 'age' => 31, ] );
Get all locks
To get all saved locks as an array:
// .. $lockerManager->getAll();
Clear all locks
To clear all locks:
// .. $lockerManager->clear();
Support
If you found an issue or had an idea please refer to this section.
Authors
- Mauro Cassani - github
License
This project is licensed under the MIT License - see the LICENSE.md file for details