PHPackages                             beatswitch/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. beatswitch/lock

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

beatswitch/lock
===============

A flexible, driver based Acl package for PHP 5.4+

0.2.0(10y ago)864335.0k↓29.8%48[20 issues](https://github.com/BeatSwitch/lock/issues)[3 PRs](https://github.com/BeatSwitch/lock/pulls)2MITPHPPHP &gt;=5.4.0

Since Nov 21Pushed 8y ago58 watchersCompare

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

READMEChangelogDependencies (3)Versions (5)Used By (2)

Lock - Acl for PHP 5.4+
=======================

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

[![Build Status](https://camo.githubusercontent.com/033baa6f62010dfe6bacf00638878487e4b4704c56b4f553c2c7d13c07d2640b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f426561745377697463682f6c6f636b2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/BeatSwitch/lock)[![Code Climate](https://camo.githubusercontent.com/5c1a08381f0a26ed262d87091b12300db0a964c9fba0339cdf3d91e5f4ce8d8b/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f426561745377697463682f6c6f636b2f6261646765732f6770612e737667)](https://codeclimate.com/github/BeatSwitch/lock)[![Test Coverage](https://camo.githubusercontent.com/b6a2fec8d65030fc2ea8b6db63a0aa765a28e1cf31d79d4b65f617d98eff072a/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f426561745377697463682f6c6f636b2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/BeatSwitch/lock/coverage)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](license.md)[![Packagist Version](https://camo.githubusercontent.com/dd10aaf427a6ea1fca482ca886dfe58bf22886ebd13451f8c51606510b788f05/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626561747377697463682f6c6f636b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beatswitch/lock)[![Total Downloads](https://camo.githubusercontent.com/f2264ea2645f83784a2d3ae4532d11fbe4def03472acc22f98becbcb3c9e9157/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626561747377697463682f6c6f636b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beatswitch/lock)

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

> I'm sad to say that Lock is currently not maintained. I won't be able to offer support or accept new contributions for the current time being. Other priorities are keeping me from putting the work into Lock that it deserves. Eventually I'll try to pick up work again but unfortunately I cannot say when. My thanks goes out to all the contributors and users.
>
> \-- Dries

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

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 beatswitch/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.

```
