2017 © Pedro Peláez
 

library thisishowirole

'This Is How I Role' is a PHP role management system that can be applied to any class.

image

divineomega/thisishowirole

'This Is How I Role' is a PHP role management system that can be applied to any class.

  • Saturday, January 27, 2018
  • by DivineOmega
  • Repository
  • 1 Watchers
  • 1 Stars
  • 125 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 19 Versions
  • 1 % Grown

The README.md

This Is How I Role (TIHIR)

'This Is How I Role' is a PHP role management system that can be applied to any class., (*1)

Installation

You can use composer to install this package. Just run composer require divineomega/thisishowirole., (*2)

Setup

Table creation

First, create a new table in your application's database to store the TIHIR roles. You can use the following SQL snippet to create the table., (*3)

CREATE TABLE IF NOT EXISTS `tihir_roles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `class_name` varchar(1000) NOT NULL,
  `foreign_id` bigint(20) NOT NULL,
  `roles` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

If you're using Laravel, you can use the following database migration to create the TIHIR roles table., (*4)

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateThisIsHowIRoleRolesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tihir_roles', function (Blueprint $table) {
            $table->increments('id');
            $table->string('class_name');
            $table->bigInteger('foreign_id');
            $table->text('roles');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('tihir_roles');
    }
}

Database connection configuration

If you're using Laravel, TIHIR will automatically use the database you've configured for your application, so you don't need to do anything here. We'll also use Eloquent to communicate with your database., (*5)

Otherwise, you need to set some environmental variables to point TIHIR towards your database. Something similar to the following will do the trick. If you're using a framework that supports it, you can put this in your .env file. If not, you can use PHP's built in putenv function., (*6)

TIHIR_DB_TYPE=mysql
TIHIR_DB_NAME=tihir_test
TIHIR_DB_HOST=192.168.1.44
TIHIR_DB_USER=tihir_test
TIHIR_DB_PASSWORD=PAMBSHcHssQqpw4A

Usage

This Is How I Role works by enhancing existing classes. This will work on any PHP class, be it a manually created class or a Laravel Eloquent model. The only requirement is that the class must have an accessible, numeric id property., (*7)

All you need to do is add two extra use lines to your class. This is shown in the example User class shown below., (*8)

require 'vendor/autoload.php';

use DivineOmega\ThisIsHowIRole\RolesTrait as Roles; // <-- Line 1

class User
{
  use Roles; // <-- Line 2

  public $id = 123;

}

This User class now has the TIHIR roles system available to it. You can now use various methods to add, remove or check for roles against this class. The snippet below shows how roles can be manipulated., (*9)

$user = new User;

$user->roles->add('can_eat_cake');
$user->roles->add('can_eat_cookies');
$user->roles->remove('can_eat_cookies');

echo 'This user can ';

if ($user->roles->has('can_eat_cake')) {
  echo 'eat cakes... ';
}

if ($user->roles->has('can_eat_cookies')) {
  echo 'eat cookies... ';
}

echo "\n";

The Versions

27/01 2018

dev-master

9999999-dev

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3 LGPL-3.0-only

The Requires

 

php library roles permissions

27/01 2018

v2.1.7

2.1.7.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL-3.0-only

The Requires

 

php library roles permissions

20/03 2017

v2.1.6

2.1.6.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

 

php library roles permissions

16/03 2017

v2.1.5

2.1.5.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

 

php library roles permissions

14/03 2017

v2.1.4

2.1.4.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

 

php library roles permissions

14/03 2017

v2.1.3

2.1.3.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

 

php library roles permissions

14/03 2017

v2.1.2

2.1.2.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

 

php library roles permissions

14/03 2017

v2.1.1

2.1.1.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

 

php library roles permissions

14/03 2017

v2.1.0

2.1.0.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

 

php library roles permissions

13/03 2017

v2.0.2

2.0.2.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

  • php >=5.5.9

 

php library roles permissions

13/03 2017

v2.0.1

2.0.1.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

  • php >=5.5.9

 

php library roles permissions

12/03 2017

v2.0.0

2.0.0.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

  • php >=5.5.9

 

php library roles permissions

20/01 2017

v1.4.2

1.4.2.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

  • php >=5.5.9

 

php library roles permissions

17/01 2017

v1.4.1

1.4.1.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

  • php >=5.6.0

 

php library roles permissions

17/01 2017

v1.4

1.4.0.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

  • php >=5.6.0

 

php library roles permissions

06/10 2016

v1.3

1.3.0.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

  • php >=5.6.0

 

php library roles permissions

09/09 2016

v1.2

1.2.0.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

  • php >=5.6.0

 

php library roles permissions

09/09 2016

v1.1

1.1.0.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

  • php >=5.6.0

 

php library roles permissions

18/07 2016

v1.0

1.0.0.0

'This Is How I Role' is a PHP role management system that can be applied to any class.

  Sources   Download

LGPL3

The Requires

  • php >=5.6.0

 

php library roles permissions