TangoMan Role Bundle
TangoMan Role Bundle provides basis for user roles / privileges management., (*1)
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:, (*2)
$ composer require tangoman/role-bundle
This command requires you to have Composer installed globally, as explained
in the installation chapter
of the Composer documentation., (*3)
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:, (*4)
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = array(
// ...
new TangoMan\RoleBundle\TangoManRoleBundle(),
);
// ...
}
}
Usage
Step 1: Create Role entity
Your Role entity must extends TangoMan\RoleBundle\Model\Role., (*5)
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use TangoMan\RoleBundle\Model\Role as TangoManRole;
/**
* Class Role
* @ORM\Entity(repositoryClass="AppBundle\Repository\RoleRepository")
* @ORM\Table(name="role")
*/
class Role extends TangoManRole
{
}
Step 2: Create Privilege entity
Your Privilege entity must extends TangoMan\RoleBundle\Model\Privilege., (*6)
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use TangoMan\RoleBundle\Model\Privilege as TangoManPrivilege;
/**
* Class Privilege
* @ORM\Entity(repositoryClass="AppBundle\Repository\PrivilegeRepository")
* @ORM\Table(name="privilege")
*/
class Privilege extends TangoManPrivilege
{
}
Step 3: Create Role and Privilege repository
<?php
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
/**
* Class RoleRepository
*
* @package AppBundle\Repository
*/
class RoleRepository extends EntityRepository
{
// ...
}
<?php
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
/**
* Class PrivilegeRepository
*
* @package AppBundle\Repository
*/
class PrivilegeRepository extends EntityRepository
{
// ...
}
Step 4: Inside User entity
Your User entity must extends TangoMan\RoleBundle\Model\User., (*7)
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use TangoMan\UserBundle\Model\User as TangoManUser;
use TangoMan\RoleBundle\Relationships\UsersHavePrivileges;
use TangoMan\RoleBundle\Relationships\UsersHaveRoles;
/**
* Class User
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
* @ORM\Table(name="user")
*/
class User extends TangoManUser
{
use UsersHavePrivileges;
use UsersHaveRoles;
// ...
public function __construct()
{
parent::__construct();
$this->roles = new ArrayCollection();
$this->privileges = new ArrayCollection();
// ...
}
}
Step 5: Update database schema
From your project folder :, (*8)
$ php bin/console doctrine:schema:update --force
Step 6: Load default roles and privileges
$ php bin/console tangoman:roles
$ php bin/console tangoman:privileges
Deprecation Warning
For Symfony 3.4 and Symfony 4 users :, (*9)
User Deprecated: The "TangoMan\RoleBundle\Model\Role" class implements "Symfony\Component\Security\Core\Role\RoleInterface" that is deprecated The RoleInterface is deprecated since version 3.3 and will be removed in 4.0. Extend the Symfony\Component\Security\Core\Role\Role class instead., (*10)
Note
If you find any bug please report here : Issues, (*11)
License
Copyright (c) 2018 Matthias Morin, (*12)
![License-MIT]
Distributed under the MIT license., (*13)
If you like TangoMan Role Bundle please star!
And follow me on GitHub: TangoMan75
... And check my other cool projects., (*14)
Matthias Morin | LinkedIn, (*15)