Download the PHP package erickskrauch/yii2-rbac-migration without Composer

On this page you can find all versions of the php package erickskrauch/yii2-rbac-migration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-rbac-migration

Yii2 RBAC Migration

Latest Version on Packagist Total Downloads

Simple and useful extension for migrations in Yii2. It allows you to perform operations on the Roles and Permission directly within the database migrations. This can be useful if you assign the Roles and Permissions for users in the application and not during the generation of RBAC.

Extension allows you to create, update and remove Roles, Permissions and Rules, and also contains useful builder to easy roles creation.

A warning: if you using constants for Roles, Permissions or Rules names, you should not to use it inside migration classes! Use simple strings with it names. Constants values during application development can change, but you old migrations should stay persistent.

Install

Via Composer

Usage

First of all we must use trait. You can do it within the migration file:

But it's somewhat uncomfortable due to the fact, that every time you will have to implement a getAuthManager() method.

Therefore, a more convenient way is to create your own base migration class, which already is use this trait and implemented the required method. For Yii2 Advanced Template this can be done by creating \console\models\Migration class with the following contents:

...and extending the migration class from the newly created:

In search of the ideal, you can override in the console application configuration migration path to the you own template file, which will be immediately with necessary base class.

In the future, you can use the methods as follows:

Available methods

RbacMigrateTrait

createPermission($name, $description = null, $ruleName = null): ItemBuilder

Create new permission, add it to authManager and return ItemBuilder object.

createRole($name, $description = null): ItemBuilder

Create new role, add it to authManager and return ItemBuilder object.

addRule($className, $name): void

Add new rule to auth manager. If class no more exists by provided $className, then it will be created and added to authManager, so you old migrations will not fail if you change or delete original rule.

updatePermission($oldName, $newName, $newDescription = false, $newRule = false): void

Method allows you to change signature of exists permission. If $newDescription passed as (bool)false, then description will not be changed. The same behavior with $newRule.

updateRole($oldName, $newName, $newDescription = false): void

Method allows you to change signature of exists role. If $newDescription passed as (bool)false, then description will not be changed.

removePermission($name): void

Remove permission by passed name.

removeRole($name): void

Remove role by passed name.

removeRule($name): void

Removing rule from auth manager. If class no more exists by provided $name, then it will be created and removed from authManager, so you old migrations will not fail if you change or delete original rule

getRole($role): ItemBuilder

Return ItemBuilder object for passed role name.

getPermission($permission): ItemBuilder

Return ItemBuilder object for passed permission name.

initRbacStructure(): void

Initialize RBAC structure. This is alternative to execute yii migrate --migrationPath=@yii/rbac/migrations/ from console

rollbackRbacStructure(): void

Call down method of RBAC migration. This is alternative to execute yii migrate/down --migrationPath=@yii/rbac/migrations/ from console

ItemBuilder

addPermission($permission): ItemBuilder

Add child permission by passed permission object or it's name. $this will be returned.

addRole($role): ItemBuilder

Add child role by passed role object or it's name. $this will be returned.

removePermission($permission): ItemBuilder

Remove child permission by passed permission object or it's name. $this will be returned.

removeRole($role): ItemBuilder

Remove child role by passed role object or it's name. $this will be returned.

Change log

Until the 1.0.0 version will be released, backwards compatibility is guaranteed only in patch releases. Minor updates may include breaking changes, so check CHANGELOG when updating the minor version.

Testing

For now I have not figured out how to test it and whether it should be tested. If you have any ideas, contributes are welcome.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of yii2-rbac-migration with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package erickskrauch/yii2-rbac-migration contains the following files

Loading the files please wait ....