mobiupbr/mup-auth-permission

提供基于JSON的ACL控制

v1.0.2 2020-12-17 03:05 UTC

This package is auto-updated.

Last update: 2024-09-17 11:32:32 UTC


README

使用composer安装

运行 composer require mobiupbr/mup-auth-permission.

示例

    $rules = [
        'Mobiup\\Order' => [
            'read' => [
                'channel' => [
                    'cha1',
                    'cha2',
                    'cha3' => [
                        'foo',
                        'bar',
                    ],
                ],
            ],
            'create',
            'update',
        ],

        'Mobiup\\Customer' => [
            'read',
            'create',
            'update',
        ],
    ];

    $acl = new ACL($rules);

    $acl->isAllowed('Mobiup\\Order', 'read'); // returns false
    $acl->isAllowed('Mobiup\\Order', 'read', 'channel'); // returns false
    $acl->isAllowed('Mobiup\\Order', 'read', 'channel', 'cha1'); // returns true
    $acl->isAllowed('Mobiup\\Order', 'read', 'channel', 'cha4'); // returns false

    $acl->isAllowed('Mobiup\\Customer', 'read'); // returns true

    $acl->getAllowance('Mobiup\\Order', 'read'); // returns false
    $acl->getAllowance('Mobiup\\Order', 'read', 'channel'); // returns ['cha1', 'cha2']
    $acl->getAllowance('Mobiup\\Order', 'read', 'channel', 'cha3'); // returns ['foo', 'bar']