atrauzzi/authoritaire

此软件包已废弃,不再维护。没有建议替代包。

适用于 Laravel 4 的简单授权软件包。

1.0 2014-02-18 14:04 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:26:11 UTC


README

Authoritaire 是尝试创建一个简单、正交的授权库。这个想法是在看到许多与项目结合过于紧密的 Laravel 4 用户库之后产生的,它们试图做很多事情。

Authoritaire 便于基于角色的权限和权限检查。许多系统只需要使用角色就可以完成,但如果需要更细粒度的控制,则可以使用权限。

使用方法

使用 Authoritaire 如同运行迁移一样简单

./artisan migrate --package="atrauzzi/authoritaire"

实现 接口 Authorizable 并将 特质 AuthorizableImpl 添加到任何需要进行权限检查的模型中。

use Atrauzzi\Authoritaire\Model\Authorizable;
use Atrauzzi\Authoritaire\Model\AuthorizableImpl;

class User implements UserInterface, RemindableInterface, Authorizable {
  use AuthorizableImpl;
  
  // ...

您可以创建新的 Permissions 并将其与 Role 关联。

$eatPlants = Atrauzzi\Authoritaire\Model\Permission::create([
  'name' => 'Eat Plants'
]);

$vegetarian = Atrauzzi\Authoritaire\Model\Role::create([
  'name' => 'Vegetarian',
  'description' => 'Does not eat meat.'
]);
$vegetarian->permissions()->save($eatPlants);

您可以使用 AuthorizableaddRole()RoleaddAuthorizable() 从任一侧授予可授权的成员资格到 Roles

$a = User::first();
$r = Atrauzzi\Authoritaire\Model\Role::where('name', '=', 'Vegetarian')->first();

// Add from authorizable-side.
$a->addRole($r);
// Or add from role-side.
$r->addAuthorizable($a);

执行检查就像询问用户是否是某个角色的成员或是否有权限访问。Authoritaire 会处理一切。

$u->is('Vegetarian');                       // true
$u->can('Eat Plants');                      // true
$u->is('Administrator');                    // false

// You can also perform checks for a set of permissions or roles.
$u->is(['Administrator', 'Vegetarian']);    // false

目前

这个版本的 Authoritaire 由于 Laravel 4 的多态关系限制 局限性 而使用了一些变通方法。因此,必须比我想象的直接操作一个连接表。

许可证

Laravel 框架是在 MIT 许可证 下开源的软件。

此项目旨在确保最大兼容性。

元数据

我对关于这个软件包的反馈和建议很感兴趣。请随时提交工单。

访问 authoritaire

Authoritaire 由 Alexander Trauzzi 制作

非常感谢 Todd FrancisVerify-L4 上的原始工作!虽然我没有保留他的大部分工作,但它主要启发了架构。