承接 dmstr/yii2-rbac-migration 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

dmstr/yii2-rbac-migration

Composer 安装命令:

composer require dmstr/yii2-rbac-migration

包简介

_____

关键字:

README 文档

README

This migration allows one to define the desired 'state' of rbac item structure.

A multidimensional array is used to define how the desired item structure should look after the migration.

Following the style of puppet config, the main attribute defining the desired or expected state of an item is the ensure parameter.

Since this type of migration change security related data, it is recommended to rather define a defensive configuration.

Installation

composer require dmstr/yii2-rbac-migration

Example usage

<?php

use dmstr\rbacMigration\Migration;
use yii\rbac\Item;

class m000000_000000_my_example_migration extends Migration {

    // define default params for al items
    public $defaultFlags = [
        'ensure' => self::PRESENT,
        'replace' => false,
    ];

    public $privileges = [
        [
            'name' => 'Role1',
            'type' => Item::TYPE_ROLE,
            'description' => 'My custom description',
            'ensure' => self::PRESENT,
            'replace' => true,
            'children' => [
                [
                    'name' => 'permission1',
                    'type' => Item::TYPE_PERMISSION,
                    'rule' => [
                       'name' => 'Rule0',
                       'class' => some\namespaced\Rule::class
                   ]
                ],
                [
                    'name' => 'permission2',
                    'type' => Item::TYPE_PERMISSION,
                    'ensure' => self::MUST_EXIST
                ],
                [
                    'name' => 'Role1',
                    'ensure' => self::PRESENT,
                    'children' => [
                        [
                            'name' => 'permission3',
                            'type' => Item::TYPE_PERMISSION
                        ]
                    ]
                ]
            ]
        ],
        [
            'name' => 'permission3',
            'type' => Item::TYPE_PERMISSION,
            'ensure' => self::ABSENT
        ],
    ];
}

config params per privilege item

  • default params for all items are defined via protected $_defaultFlagsStruct array
  • default params can be defined/overridden per migration instance via public $defaultFlags
  • params which are set directly at the items have the highest priority

defined params are merged per item.

param value required default description
name string yes null rbac item name
type Item::TYPE_ROLE or Item::TYPE_PERMISSION no Item::TYPE_PERMISSION rbac item type
ensure see ensure flags no self::NEW ensure state of the item after and before migration
replace boolean no false weather item will be updated if exists
rule array no none array of name, class properties that will be used as rule for this item
description string no none description property of the item

valid flags for ensure param

flag desc
self::NEW new item will be created, error if already exists
self::MUST_EXIST item must exist, error if not
self::PRESENT ensure item exists, if replace == true update/replace, otherwise leave as is
self::ABSENT if item extists item will be removed. Handle with care!

hints for self::ABSENT

  • If defined as item param, the item will be removed regardless of its position.
  • So if you define ensure => self::ABSENT in child items, NOT only the child relation but the item will be removed!
  • if auth items are defined in DB and the auth tables has FK with cascade, child relations for this item may be deleted by the db.

hints for rules

  • if defined rules are assigned to item "by name".
  • if not exists it will be created with the given class property.
  • if rule with given name already exists and replace is set to true, rule will be updated, otherwise existing rule will be used.

deprecated item params

the params _exists and _force are deprecated but still valid and will be replaced with new params scheme

deprecated param converted to
_exists 'ensure' => self::MUST_EXIST
_force 'ensure' => self::PRESENT, 'replace' => true

shortcut syntax for mass assignments

to be able to quickly define mass assignments a special shortcut syntax where item is just a string can be used. The string will be set as item['name'] property, all other params are used from (defined) defaults.

Example:

    public $defaultFlags = [
        'type'    => Item::TYPE_PERMISSION,
        'ensure'  => self::MUST_EXIST,
        'replace' => false,
    ];
    public $privileges = [
            [
            'name'        => 'PublicationEditor',
            'type'        => Item::TYPE_ROLE,
            'ensure'      => self::PRESENT,
            'replace'     => true,
            'description' => 'Create, edit, delete publication items.',
            'children'    => [
                'publication_default',
                'publication_crud_index',
                'publication_crud_publication-item_create',
                'publication_crud_publication-item_delete',
                'publication_crud_publication-item_index',
                'publication_crud_publication-item_update',
                'publication_crud_publication-item_view',
            ]
        ]
    ];

safeDown()

These auth migrations can not be reverted.

Built by dmstr

dmstr/yii2-rbac-migration 适用场景与选型建议

dmstr/yii2-rbac-migration 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35.41k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 05 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 dmstr/yii2-rbac-migration 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

与 dmstr/yii2-rbac-migration 相关的其它包

同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-05-11