PHP code example of dmstr / yii2-rbac-migration

1. Go to this page and download the library: Download dmstr/yii2-rbac-migration library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dmstr / yii2-rbac-migration example snippets




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
        ],
    ];
}

    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',
            ]
        ]
    ];