PHPackages                             dusta/lock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. dusta/lock

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

dusta/lock
==========

A flexible, driver based Acl package for PHP 5.6+

v0.3.0(7y ago)0547MITPHPPHP &gt;=5.6.0

Since Nov 21Pushed 7y ago1 watchersCompare

[ Source](https://github.com/dusta/lock)[ Packagist](https://packagist.org/packages/dusta/lock)[ Docs](https://github.com/dusta/lock)[ RSS](/packages/dusta-lock/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (3)Versions (6)Used By (0)

Lock - Acl for PHP 5.6+
=======================

[](#lock---acl-for-php-56)

[![Build Status](https://camo.githubusercontent.com/3831c9e28b0c896a8e29cc26ee77b8001a9ae37008820cdfb0b2aa7b5ed597d3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f64757374612f6c6f636b2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/dusta/lock)[![Code Climate](https://camo.githubusercontent.com/70e0ab046d898fd4d7fc1ff0e3f8e1dcf7066ae7d114e67fceea342019055f88/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f64757374612f6c6f636b2f6261646765732f6770612e737667)](https://codeclimate.com/github/dusta/lock)[![Test Coverage](https://camo.githubusercontent.com/b90f8b8759b70a12640a2339d7e33eb9a8d4856ebe4332acbcc0cb9592eae6c0/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f64757374612f6c6f636b2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/dusta/lock/coverage)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](license.md)[![Packagist Version](https://camo.githubusercontent.com/83d5698364309e9bc1aef16bfd6de8c0795494eec304cb35c6f55f66c10aa235/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64757374612f6c6f636b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dusta/lock)[![Total Downloads](https://camo.githubusercontent.com/291666ca40145d7c8f1be47c9f4560b9f116734ed2efb016e151fc67f1a1dd95/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64757374612f6c6f636b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dusta/lock)

[![](https://camo.githubusercontent.com/1ebe9a740468ca0611d55063d626b9dadb2601624eac8260e7245431fdb9915e/68747470733a2f2f73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6173736574732e626561747377697463682e636f6d2f6c6f636b5f62616e6e65722e706e67)](https://camo.githubusercontent.com/1ebe9a740468ca0611d55063d626b9dadb2601624eac8260e7245431fdb9915e/68747470733a2f2f73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6173736574732e626561747377697463682e636f6d2f6c6f636b5f62616e6e65722e706e67)

Lock is a flexible, driver based **Acl** package for **PHP 5.6+**.

Created by [Dries Vints](https://twitter.com/driesvints). Made possible thanks to [BeatSwitch](https://beatswitch.com). Inspired by [Authority](https://github.com/machuga/authority) by [Matthew Machuga](https://twitter.com/machuga). Logo by [Jerry Low](http://www.jerrylow.com).

Table of Contents
-----------------

[](#table-of-contents)

- [Terminology](#terminology)
- [Features](#features)
- [Introduction](#introduction)
- [Drivers](#drivers)
- [Roadmap](#roadmap)
- [Installation](#installation)
- [Usage](#usage)
    - [Implementing the Caller contract](#implementing-the-caller-contract)
    - [Working with a static driver](#working-with-a-static-driver)
    - [Working with a persistent driver](#working-with-a-persistent-driver)
    - [Setting and checking permissions](#setting-and-checking-permissions)
    - [Clearing permissions](#clearing-permissions)
    - [Setting an action alias](#setting-an-action-alias)
    - [Setting a God caller](#setting-a-god-caller)
    - [Working with roles](#working-with-roles)
    - [Working with conditions](#working-with-conditions)
    - [Retrieving allowed or denied resources](#retrieving-allowed-or-denied-resources)
    - [Using the LockAware trait](#using-the-lockaware-trait)
- [Api](#api)
- [Building a driver](#building-a-driver)
    - [Testing your driver](#testing-your-driver)
- [Maintainer](#maintainer)
- [Contributing](#contributing)
- [Changelog](#changelog)
- [License](#license)

Terminology
-----------

[](#terminology)

- `Lock`: An acl instance for a subject. This package currently ships with a `CallerLock` and a `RoleLock`
- `Caller`: An identity object that can have permissions to do something
- `Driver`: A storage system for permissions which can either be static or persistent
- `Permission`: A permission holds an action and an optional (unique) resource. Can be either a `Restriction` or a `Privilege`
- `Restriction`: A restriction denies you from being able to perform an action (on an optional resource)
- `Privilege`: A privilege allows you to perform an action (on an optional resource)
- `Action`: An action is something you are either allowed or denied to do
- `Resource`: A resource can be an object where you can perform one or more actions on. It can either target a certain type of resource or a specific resource by its unique identifier
- `Role`: A role can also hold multiple permissions. A caller can have multiple roles. Roles can inherit permissions from other roles

Features
--------

[](#features)

- Flexible acl permissions for multiple identities (callers)
- Static or persistent drivers to store permissions
- Action aliases
- Roles
- Conditions (Asserts)
- Easily implement acl functionality on your caller or role with a trait

Introduction
------------

[](#introduction)

Lock differs from other acl packages by trying to provide the most flexible way for working with multiple permission callers and storing permissions.

By working with Lock's `Caller` contract you can set permissions on multiple identities.

The `Driver` contract allows for an easy way to store permissions to a persistent or static storage system. A default static `ArrayDriver` ships with this package. Check out the list below for more drivers which have already been prepared for you. Or build your own by implementing the `Driver` contract.

You can set and check permissions for resources by manually passing along a resource's type and (optional) identifier or you can implement the `Resource` contract onto your objects so you can pass them along to lock more easily.

The `Manager` allows for an easy way to instantiate new `Lock` instances, set action aliases or register roles.

Drivers
-------

[](#drivers)

If you need a framework-specific implementation, pick one of the already prepared drivers below.

- ArrayDriver (ships with this package)
- [Laravel 5](https://github.com/BeatSwitch/lock-laravel)

Roadmap
-------

[](#roadmap)

- Group Permissions
- More drivers (Symfony, Zend Framework, Doctrine, ...)
- Event Listeners

Installation
------------

[](#installation)

Install this package through Composer.

```
$ composer require dusta/lock
```

Usage
-----

[](#usage)

### Implementing the Caller contract

[](#implementing-the-caller-contract)

Every identity which should have permissions to do something must implement the `BeatSwitch\Lock\Callers\Caller` contract. The `Caller` contract identifies a caller by requiring it to return its type and its unique identifier. Let's look at an example below.

```
