Download the PHP package northern/acl without Composer

On this page you can find all versions of the php package northern/acl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package acl

ACL

A simple Role based Access Control List build on Zend Framework 2 ACL.

Introduction

Northern\Acl is a role based ACL that allows for easy definition of permissions for specific roles. Roles can inherit from other roles. Simply by storing a role against a user, using that role would allow you to test if that role is permitted a certain access criteria.

Installation

To use Northern\Acl add it to your project using Composer:

"northern/acl": "1.*"

Usage

To use Northern\Acl start by defining a permissions list. We can start with an empty list:

$permissions = [
   'roles'     => [],
   'resources' => [],
   'rules'     => [],
];

Our permissions list contains three top-level requirements, roles, resources and rules. The idea behind a role based ACL is that a specific role has access to resources through specified rules. Don't confuse the elements you define in this list with 'real' objects in your application. The permissions list is simply a structure (or model) we test against, it is static and therefore it doesn't need to be stored in a database but can simply be defined in a business object in your application as part of your business rules.

Let's add some permissions..

For the purpose of this demonstration we define four roles; guest, member, author and admin. For the sake of argument, we define the resources for a simple blog so we have post and comment as resources:

$permissions = [
   'roles'     => [
      ['name' => 'guest'],
      ['name' => 'member', 'parent' => 'guest'],
      ['name' => 'author', 'parent' => 'member'],
      ['name' => 'admin',  'parent' => 'author'],
   ],
   'resources' => [
      ['name' => 'post'],
      ['name' => 'comment'],
   ],
   'rules'     => [],
];

Easy as. Now lets define a rule that allows guests to view both posts and comments:

$permissions = [
   'roles'     => [
      ['name' => 'guest'],
      ['name' => 'member', 'parent' => 'guest'],
      ['name' => 'author', 'parent' => 'member'],
      ['name' => 'admin',  'parent' => 'author'],
   ],
   'resources' => [
      ['name' => 'post'],
      ['name' => 'comment'],
   ],
   'rules'     => [
      [
         'access'      => 'allow',
         'role'        => 'guest',
         'permissions' => ['view'],
         'resources'   => ['post', 'comment'],
      ]
   ],
];

As you can see, the rule is pretty straight forward. both permissions and resources can either be set as single values or as an array. Let's create a rule that allows members to create comments:

$permissions = [
   'roles'     => [
      ['name' => 'guest'],
      ['name' => 'member', 'parent' => 'guest'],
      ['name' => 'author', 'parent' => 'member'],
      ['name' => 'admin',  'parent' => 'author'],
   ],
   'resources' => [
      ['name' => 'post'],
      ['name' => 'comment'],
   ],
   'rules'     => [
      [
         'access'      => 'allow',
         'role'        => 'guest',
         'permissions' => ['view'],
         'resources'   => ['post', 'comment'],
      ], [
         'access'      => 'allow',
         'role'        => 'member',
         'permissions' => ['create'],
         'resources'   => ['comment'],
      ]
   ],
];

Great. Now let's fill in the rest of the permissions:

$permissions = [
   'roles'     => [
      ['name' => 'guest'],
      ['name' => 'member', 'parent' => 'guest'],
      ['name' => 'author', 'parent' => 'member'],
      ['name' => 'admin',  'parent' => 'author'],
   ],
   'resources' => [
      ['name' => 'post'],
      ['name' => 'comment'],
   ],
   'rules'     => [
      [
         'access'      => 'allow',
         'role'        => 'guest',
         'permissions' => ['view'],
         'resources'   => ['post', 'comment'],
      ], [
         'access'      => 'allow',
         'role'        => 'member',
         'permissions' => ['create'],
         'resources'   => ['comment'],
      ], [
         'access'      => 'allow',
         'role'        => 'author',
         'permissions' => ['create', 'edit', 'delete'],
         'resources'   => ['post'],
      ], [
         'access'      => 'allow',
         'role'        => 'admin',
         'permissions' => NULL,
         'resources'   => NULL,
      ]
   ],
];

We added the author permissions and set the admin permissions to allow all access on all resources.

To use these permissions we need to load them into the ACL, like this:

$acl = new \Northern\Acl\Acl();
$acl->loadPermissions( $permissions );

The $acl instance will allow us to test for permissions through the isAllowed method. However, the true power of Northern\Acl is in the Permissions class of which need to create a subclass:

class Permissions extends \Northern\Acl\Permissions {

    public function getRoles()
    {
       return ['guest', 'member', 'author', 'admin'];
    }

    public function getResources()
    {
       return ['post', 'comment'];
    }

    public function getRules()
    {
          return ['create', 'view', 'edit', 'delete'];
    }

}

We can now use this Permissions class to do some magic:

$acl = new \Northern\Acl\Acl();
$acl->loadPermissions( $permissions );

$authorPermissions = new Permissions( $acl, 'author' );

$authorPermissions->canCreatePost();
// TRUE!

As you can see. The Permissions instance allows you to test for permissions on a role through magic methods.

That's all folks!


All versions of acl with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.3
psr/log Version 1.0.0
northern/common Version 2.*
zendframework/zend-permissions-acl Version 2.3.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package northern/acl contains the following files

Loading the files please wait ...