Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A simple API permissions using binary operators.
PHP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lila
.gitignore
README.textile
User.php
index.php

README.textile

Lila

This is based on lila

How to use

In Permissions class add your permissions on array, like this:

   
private static $permissions = array(
    'read' => 1,
    'write' => 2
);`

Create a class that implements HasPermission. This class need a integer field to store a value of premissions.

class User implements HasPermission{
    
    private $permission = 0;
    
    public function getPermission() {
        return $this->permission;
    }
    public function setPermission($permission) {
        $this->permission = $permission;
    }
}	

Instantiate a Lila or LilaPermissionAdapter to manage permissions

Adding permission…

whit Lila


$user = new User();
$lila = new Lila();

$r = Permissions::get(‘read’);
$w = Permissions::get(‘write’);

$user→setPermission($lila→addPermission($$user→getPermission(), $r));
$user→setPermission($lila→addPermission($$user→getPermission(), $w));

with LilaPermissionAdapter


$user = new User();

$lilaAdapter = new LilaPermissionAdapter($user);

$r = Permissions::get(‘read’);
$w = Permissions::get(‘write’);

$lilaAdapter→addPermission($r);
$lilaAdapter→addPermission($w);

Checking permissions…

with Lila


$w = Permissions::get(‘write’);
if($lila→containsPermission($user→getPermission(), $r)){
//Allowed
}

with LilaPermissionAdapter

$w = Permissions::get('write');
if ($lilaAdapter->hasPermission($w)) {
    //Allowed
}

Something went wrong with that request. Please try again.