2017 © Pedro Peláez
 

library authorize

A package for basic ACL/role

image

berg/authorize

A package for basic ACL/role

  • Tuesday, September 12, 2017
  • by mrberggg
  • Repository
  • 1 Watchers
  • 0 Stars
  • 62 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

Authorizer

A super simple role-based authorization package. The examples here use Eloquent but the library is framework-agnostic., (*2)

Installation

composer require berg/authorizer, (*3)

Usage

Add the use statement for the trait to your user model:, (*4)

use Berg\Authorizer\AuthorizerTrait;

This trait requires that the user class has a method named getRoles() that will return an array of your role names. You can then access the is and hasAccessTo methods. Usage:, (*5)

$user->is('admin');

$model = new ModelName($id);
$user->hasAccessTo($model);

is and hasAccessTo both return a boolean value. hasAccessTo requires that the model you pass as an argument contains a method authorize(User $user);., (*6)

is(string $roleName)

Example checking role:, (*7)

if($user->is('admin')) {}

hasAccessTo(User $user)

To make a model authorizable, add the Authorizable interface to your model. This interface requires you add a single method, authorize($user) to your model. Add any required authorization logic in that method and return a boolean value., (*8)

class Car 
{
    public function authorize(User $user)
    {
        return $this->userId === $user->id;
    }
}

$carId = 1;
$car = new Car($carId);
if($user->hasAccessTo($car)) {}

The Versions

12/09 2017

dev-master

9999999-dev https://github.com/mrberggg/authorizer

A package for basic ACL/role

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

acl php authorize

07/10 2015

0.1.1

0.1.1.0 https://github.com/mrberggg/authorizer

A package for basic ACL/role

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

acl php authorize

06/05 2015

0.1

0.1.0.0 https://github.com/mrberggg/authorizer

A package for basic ACL/role

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

acl php authorize