2017 © Pedro Peláez
 

library locker-manager

Locker Manager

image

mauretto78/locker-manager

Locker Manager

  • Thursday, November 16, 2017
  • by mauretto78
  • Repository
  • 1 Watchers
  • 0 Stars
  • 109 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 17 % Grown

The README.md

Simple Locker Manager

Scrutinizer Code Quality Codacy Badge license Packagist, (*1)

This library is suitable for you if you need to simple lock system., (*2)

Installation

composer require mauretto78/locker-manager

Basic Usage

Instantiate LockerManager

To instantiate the LockerManager you must inject an implementation of LockerStoreInterface. You can use:, (*3)

  • FLockerStore
  • PdoLockerStore
  • RedisLockerStore

Take a look:, (*4)

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., (*5)

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., (*6)

Please consider this example:, (*7)

// ..

// 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:, (*8)

// ..

$lockerManager->getAll();

Clear all locks

To clear all locks:, (*9)

// ..

$lockerManager->clear();

Support

If you found an issue or had an idea please refer to this section., (*10)

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details, (*11)

The Versions