Skip to content

mauretto78/locker-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Locker Manager

Scrutinizer Code Quality Codacy Badge license Packagist

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

License

This project is licensed under the MIT License - see the LICENSE.md file for details