berg/authorize 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

berg/authorize

最新稳定版本:0.1.1

Composer 安装命令:

composer require berg/authorize

包简介

A package for basic ACL/role

README 文档

README

Build Status

Authorizer

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

Installation

composer require berg/authorizer

Usage

Add the use statement for the trait to your user model:

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:

$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);.

is(string $roleName)

Example checking role:

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.

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

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

统计信息

  • 总下载量: 85
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-06