liberty_code / role_model
Requires
- php: ~7 || ~8
- liberty_code/item_browser: ^1.0.
- liberty_code/library: ^1.0.
- liberty_code/model: ^1.0.
- liberty_code/role: ^1.0.
- liberty_code/sql: ^1.0.
- liberty_code/validation: ^1.0.
This package is auto-updated.
Last update: 2024-09-28 03:13:28 UTC
README
描述
库包含权限和角色模型组件,用于管理访问。
要求
- 脚本语言:PHP:版本 7 或 8
框架库实现要求
库仓库:liberty_code/validation:版本 1.0
标准规则实现(或等效)
实体上提供的验证器,必须包含所有标准规则,添加到其规则集合中。
验证器规则实现(或等效)
实体上提供的验证器,必须包含所有验证器规则,添加到其规则集合中。每个验证器规则必须使用验证器,与实体上提供的验证器相同的实现。
库仓库:liberty_code/model:版本 1.0
验证实体规则实现(或等效)
实体上提供的验证器,必须包含所有实体规则,添加到其规则集合中。
库仓库:liberty_code/sql:版本 1.0
验证 SQL 规则实现(或等效)
实体上提供的验证器,必须包含所有 SQL 规则,添加到其规则集合中。
安装
有几种可能的方法
Composer
要求
需要安装 Composer。更多信息: https://getcomposer.org
命令:移动到项目根路径
cd "<project_root_path>"
命令:安装
php composer.phar require liberty_code/role_model ["<version>"]
注意
包含 vendor
如果项目使用 composer,则必须包含 vendor
require_once('<project_root_path>/vendor/autoload.php');
配置
安装命令允许在 composer 文件中添加:
{ "require": { "liberty_code/role_model": "<version>" } }
包含
下载
- 下载以下仓库。
- 将其放在仓库根路径上。
包含源代码
require_once('<repository_root_path>/include/Include.php');
使用
主题
主题允许设计主题基础,可用于角色和权限实体。
元素
主题
允许设计主题基础,用于角色和权限实体。
权限
权限实体允许使用实体来设计权限。
元素
PermissionEntity
扩展了配置实体的保存功能。使用实体来设计权限,以授权特定操作。
PermissionEntityCollection
扩展了固定实体集合功能。允许设计权限实体集合。
PermissionEntityFactory
扩展了固定实体工厂功能。允许设计权限工厂,以提供指定配置的权限实体对象。
SubjPermEntity
扩展了权限实体功能。与特定主题相关。
SubjPermEntityCollection
扩展了权限实体集合功能。用于存储主题权限实体。
SubjPermEntityFactory
扩展了权限实体工厂功能。提供主题权限实体对象。
SubjPermEntityRepository
扩展了固定多仓库功能。允许设计主题权限实体仓库,以在持久化中保存主题权限实体数据。
SubjPermEntityCollectionRepository
扩展了固定多集合仓库功能。允许设计主题权限实体集合仓库,以在持久化中保存主题权限实体集合数据。
SqlSubjPermEntity
扩展了主题权限实体功能。使用 SQL 规则进行属性验证。
SqlSubjPermEntityFactory
扩展了主题权限实体工厂功能。提供 SQL 主题权限实体对象。
SqlSubjPermEntityRepository
扩展了主题权限实体仓库功能。使用 SQL 表持久化作为持久化。
SqlSubjPermEntityCollectionRepository
扩展主题权限实体集合存储库功能。使用SQL表持久化作为存储。
// Get subject permission factory
use liberty_code\role_model\permission\subject\model\SubjPermEntityFactory;
$subjPermEntityFactory = new SubjPermEntityFactory($provider);
...
// Get permission builder
use liberty_code\role_model\permission\build\model\DefaultBuilder;
$permissionBuilder = new DefaultBuilder($permSpec, $subjPermEntityFactory);
...
// Get subject permission collection
use liberty_code\role_model\permission\subject\model\SubjPermEntityCollection;
$subjPermEntityCollection = new SubjPermEntityCollection();
...
// Hydrate subject permission collection
$permissionBuilder->hydratePermissionCollection($subjPermEntityCollection);
...
foreach($subjPermEntityCollection->getTabPermissionKey() as $permissionKey) {
echo($subjPermEntityCollection->getObjPermission($permissionKey)->getStrPermissionKey() .'<br />');
}
/**
* Show:
* Permission key 1
* ...
* Permission key N
*/
...
权限主体
权限主体允许设计权限主体基础,可用于主题权限实体。
元素
PermissionSubject
扩展权限主体和主题功能。允许设计权限主体,可用于主题权限实体。
角色
角色实体允许使用实体设计角色。
元素
RolePermEntity
扩展权限实体功能。与特定角色相关。
RolePermEntityCollection
扩展权限实体集合功能。用于存储角色权限实体。
RolePermEntityFactory
扩展权限实体工厂功能。提供角色权限实体对象。
RolePermEntityRepository
扩展固定多存储库功能。允许设计角色权限实体存储库,以保存从角色权限实体持久化的数据。
RolePermEntityCollectionRepository
扩展固定多集合存储库功能。允许设计角色权限实体集合存储库,以保存从角色权限实体集合持久化的数据。
SqlRolePermEntity
扩展角色权限实体功能。使用SQL规则进行属性验证。
SqlRolePermEntityFactory
扩展角色权限实体工厂功能。提供SQL角色权限实体对象。
SqlRolePermEntityRepository
扩展角色权限实体存储库功能。使用SQL表持久化作为存储。
SqlRolePermEntityCollectionRepository
扩展角色权限实体集合存储库功能。使用SQL表持久化作为存储。
RoleEntity
扩展保存配置实体功能。使用实体设计角色。
RoleEntityCollection
扩展固定实体集合功能。允许设计角色实体集合。
RoleEntityFactory
扩展固定实体工厂功能。允许设计角色工厂,以提供从指定配置的实体对象。
RoleEntityRepository
扩展固定多存储库功能。允许设计角色实体存储库,以保存从角色实体持久化的数据。
RoleEntityCollectionRepository
扩展固定多集合存储库功能。允许设计角色实体集合存储库,以保存从角色实体集合持久化的数据。
SqlRoleEntity
扩展角色实体功能。使用SQL规则进行属性验证。
SqlRoleEntityFactory
扩展角色实体工厂功能。提供SQL角色实体对象。
SqlRoleEntityRepository
扩展角色实体存储库功能。使用SQL表持久化作为存储。
SqlRoleEntityCollectionRepository
扩展角色实体集合存储库功能。使用SQL表持久化作为存储。
// Get role permission factory
use liberty_code\role_model\role\permission\model\RolePermEntityFactory;
$rolePermEntityFactory = new RolePermEntityFactory($provider);
...
// Get permission builder
use liberty_code\role_model\permission\build\model\DefaultBuilder;
$permissionBuilder = new DefaultBuilder($permSpec, $rolePermEntityFactory);
...
// Get role factory
use liberty_code\role_model\role\model\RoleEntityFactory;
$roleEntityFactory = new RoleEntityFactory();
...
// Get role builder
use liberty_code\role\role\build\model\DefaultBuilder;
$roleBuilder = new DefaultBuilder(
$roleEntityFactory,
array(
$permissionBuilder
)
);
...
// Get role collection
use liberty_code\role_model\role\model\RoleEntityCollection;
$roleEntityCollection = new RoleEntityCollection();
...
// Hydrate role collection
$roleBuilder->hydrateRoleCollection($roleEntityCollection);
...
foreach($roleEntityCollection->getTabRoleName() as $roleName) {
echo($roleEntityCollection->getObjRole($roleName)->getStrRoleName() .'<br />');
}
/**
* Show:
* Role name 1
* ...
* Role name N
*/
...
角色主体
角色主体允许设计角色主体,可用于角色实体。
元素
RoleSubject
扩展角色主体和主题功能。允许设计角色主体,可用于角色实体。
角色浏览器
浏览器允许提供从指定浏览配置的角色实体。
RoleBrowserEntity
扩展验证配置实体功能。允许定义属性,以搜索角色实体。
RoleBrowserRepository
允许从指定的角色浏览器实体或指定的浏览配置中加载数据。
SqlRoleBrowserRepository
扩展角色浏览器存储库功能。使用SQL表浏览器来加载角色实体。
// Get role browser entity
use liberty_code\role_model\role\browser\model\RoleBrowserEntity;
$roleBrowserEntity = new RoleBrowserEntity(array(), $validator);
...
// Hydrate role browser entity
$roleBrowserEntity->intAttrItemCountPage = 50; // Select 50 roles per page
$roleBrowserEntity->intAttrPageIndex = 0; // Select Page 1
$roleBrowserEntity->strAttrCritLikeName = '...' // Select result where role name like '...'
$roleBrowserEntity->$strAttrSortName = 'asc' // Sort result by ascending role name
...
// Get role browser repository
use liberty_code\role_model\role\browser\sql\model\repository\SqlRoleBrowserRepository;
$roleBrowserRepository = new SqlRoleBrowserRepository(
$sqlTableBrowser,
$sqlRoleEntityCollectionRepository
);
...
// Load role collection
$roleBrowserRepository->loadFromEntity($roleEntityCollection, $roleBrowserEntity);
...