定制 jcpires/cakephp3-aclmanager 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

jcpires/cakephp3-aclmanager

Composer 安装命令:

composer require jcpires/cakephp3-aclmanager

包简介

An acl-manager plugin for CakePhp3

README 文档

README

Software License CakePHP 3 Build Status

Install

    Composer require jcpires/cakephp3-aclmanager

or on composer.json

    "jcpires/cakephp3-aclmanager": "dev-master"

Requirements

CakePhp ACL

How to

Build your Acos

First you need to build your acos, to do, you need to add this lines where you want. There are two way:

  • By an event:

        use JcPires\AclManager\Event\PermissionsEditor;
    
        $this->eventManager()->on(new PermissionsEditor());
        $acosBuilder = new Event('Permissions.buildAcos', $this);
        $this->eventManager()->dispatch($acosBuilder);
    
  • By the component

        $this->loadComponent('JcPires/AclManager.AclManager');
        $this->AclManager->acosBuilder();
    

NB: !!! Don't forget to delete those lines after building !!!

Add permissions when creating a new group

!!! Be caution, to works, you need first a first level ARO with base node full granted like a Super Admin like this on the aros_acos table: create:1 read: 1 update: 1 delete: 1!!!

On your Admin/GroupsController.php

    use JcPires\AclManager\Event\PermissionsEditor;

Add basics permissions, on your action add

    if ($this->Groups->save($group)) {

        if (isset($this->request->data['parent_id'])) {
            $parent = $this->request->data['parent_id'];
        } else {
            $parent = null;
        }

        $this->eventManager()->on(new PermissionsEditor());
        $perms = new Event('Permissions.addAro', $this, [
            'Aro' => $group,
            'Parent' => $parent,
            'Model' => 'Groups'
        ]);
        $this->eventManager()->dispatch($perms);
    }

Edit permissions

  1. On your action edit()
we need to get all acos "not really necessary is just an automatic array builder":

```
    $this->loadComponent('JcPires/AclManager.AclManager');
    $EditablePerms = $this->AclManager->getFormActions();
```

If you to exclude some actions for the form like ajax actions, you have to add a static property

On the specified controller like PostController or BlogController, ...:

```
    public static $AclActionsExclude = [
        'action1',
        'action2',
        '...'
    ];
```

You will have an array with all acos's alias indexed by the controller aco path like:

```
    'Blog' => [
        'add',
        'edit',
        'delete
    ],
    'Post' => [
        'add',
        'edit',
        'delete'
    ],
    'Admin/Post' => [
        'add',
        'edit',
        'delete'
    ]
```
  1. Build your form
First if you want to use the AclManager Helper

```
    public $helpers = [            
            'AclManager' => [
                        'className' => 'JcPires/AclManager.AclManager'
                    ]
        ];

    // on your action in your controllerPath
    $EditablePerms = $this->AclManager->getFormActions();
```

an exemple with an Acl helper for checking if permissions are allowed or denied:

```
<?php foreach ($EditablePerms as $Acos) :?>
    <?php foreach ($Acos as $controllerPath => $actions) :?>
        <?php if (!empty($actions)) :?>
            <h4><?= $controllerPath ;?></h4>
            <?php foreach ($actions as $action) :?>
                <?php ($this->AclManager->checkGroup($group, $controllerPath.'/'.$action)) ? $val = 1 : $val = 0 ?>
                <?= $this->Form->label($controllerPath.'/'.$action, $action);?>
                <?= $this->Form->select($controllerPath.'/'.$action, [0 => 'No', 1 => 'Yes'], ['value' => $val]) ;?>
            <?php endforeach ;?>
        <?php endif;?>
    <?php endforeach ;?>
<?php endforeach ;?>
```

render:

```
    <select name="App/Blog/add">
        <option value="0">No</option>
        <option value="1" selected>Yes</option>
    </select>
```

If you don't use the Array Builder you need to specified your input name like aco path: App/Blog/add or App/Admin/Blog/add ... :base/:folder/:subfolder/:controller/:action "Folder and subfolder can be empty"

  1. Update new permissions
```

    if ($this->request->is('post')) {

        $this->eventManager()->on(new PermissionsEditor());
        $perms = new Event('Permissions.editPerms', $this, [
            'Aro' => $group,
            'datas' => $this->request->data
        ]);
        $this->eventManager()->dispatch($perms);
    }

```

data need to be like this 'aco path' => value "0 deny / 1 allow"

```
    'App/Blog/add' => 0
    'App/Blog/edit' => 1
    ...
```

jcpires/cakephp3-aclmanager 适用场景与选型建议

jcpires/cakephp3-aclmanager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.83k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2015 年 05 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「plugin」 「cakephp」 「acl」 「cake3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jcpires/cakephp3-aclmanager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jcpires/cakephp3-aclmanager 我们能提供哪些服务?
定制开发 / 二次开发

基于 jcpires/cakephp3-aclmanager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 8
  • 开发语言: PHP

其他信息

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