scento/merowinger

此包已被废弃,不再维护。未建议替代包。

控制keymaker的PHP ACL库。

1.0.3 2016-09-02 08:10 UTC

This package is not auto-updated.

Last update: 2020-01-24 16:13:59 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License

Merowinger 是一个PHP ACL库,以简单和极简的方式控制keymaker。此库提供以下功能

  • 角色管理
  • 角色继承
  • 资源和动作管理
    • 角色
    • 资源
    • 动作
  • ACL序列化

安装

可以使用 composer 安装此库。此包仅需要 PHP >=7.0.0json 扩展才能正常工作。如果您想在不使用 composer 的情况下使用 Merowinger,可以将自动加载器配置为包含项目根目录中 src/ 目录下的 Merowinger\ 命名空间中的文件。

示例

<?php
use Merowinger\Access;
use Merowinger\Acl;
use Merowinger\Role;

$acl = new Acl();
$acl->setDefaultAccess(Access::DENY);

//Create Roles
$applications = new Role('Application');
$humans = new Role('Human');

$rebels = new Role('Rebel');
$rebels->inherits($humans);

$population = new Role('Population');
$population->inherits($humans);

$merowinger = new Role('Merowinger');
$merowinger->inherits($applications);

$agents = new Role('Agent');
$agents->inherits($applications);
$agents->inherits($humans);

$neo = new Role('Neo');
$neo->inherits($rebels);

//Register Roles And Resources
$acl->addResource('Matrix', ['liveIn', 'see', 'control', 'destroy']);
$acl->addResource('Keymaker', ['know', 'control']);

$acl->addRole($applications);
$acl->addRole($humans);

$acl->addRole($rebels);
$acl->addRole($population);
$acl->addRole($agents);

$acl->addRole($neo);
$acl->addRole($merowinger);

//Grant permissions
$acl->allow('Population', 'Matrix', 'liveIn');
$acl->allow('Application', 'Matrix', ['control', 'see']);
$acl->allow('Rebel', 'Keymaker', 'know');
$acl->allow('Rebel', 'Matrix', ['liveIn', 'see']);
$acl->allow('Neo', 'Matrix'); //Grant full access to resource matrix
$acl->allow('Merowinger', 'Keymaker', ['know', 'control']);
$acl->allow('Agent', 'Matrix', 'control');

//Check whether Neo can destroy the matrix
$acl->isAllowed('Neo', 'Matrix', 'destroy'); //returns Access::ALLOW

//Check whether the population can control the matrix
$acl->isAllowed('Population', 'Matrix', 'control'); //returns Access::DENY

开发

对本项目的所有贡献都应遵循 PSR-2 规范。除此之外,我们还使用 PHPDoc 注释并编写 PHPUnit 测试。以下命令可以用来在本地执行所有测试。请在提交之前执行此操作。

vendor/bin/phpunit --debug --verbose --configuration test/unit.xml

此仓库遵循 语义版本控制范式。所有主要更改都记录在 变更日志 中,遵循 保持变更日志原则

许可协议

此库采用 MIT 许可协议 许可。