This library is suitable for you if you need to simple lock system.
composer require mauretto78/locker-manager
To instantiate the LockerManager you must inject an implementation of LockerStoreInterface. You can use:
FLockerStorePdoLockerStoreRedisLockerStore
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);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,
]
);To get all saved locks as an array:
// ..
$lockerManager->getAll();To clear all locks:
// ..
$lockerManager->clear();If you found an issue or had an idea please refer to this section.
- Mauro Cassani - github
This project is licensed under the MIT License - see the LICENSE.md file for details
