2017 © Pedro Peláez
 

symfony-bundle role-hierarchy-bundle

Symfony2 Role Hierarchy Bundle

image

spomky-labs/role-hierarchy-bundle

Symfony2 Role Hierarchy Bundle

  • Friday, November 4, 2016
  • by Spomky
  • Repository
  • 2 Watchers
  • 8 Stars
  • 580 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 2 % Grown

The README.md

Role Hierarchy

Scrutinizer Quality Score Build Status HHVM Status, (*1)

SensioLabsInsight, (*2)

Latest Stable Version Total Downloads Latest Unstable Version License, (*3)

Prerequisites

This version of the bundle requires:, (*4)

  • Symfony 2.8 or 3.0+
  • PHP 5.6+

It has been successfully tested using PHP 5.6 to PHP 7.0 and HHVM under Symfony 2.8 to 3.0., (*5)

Installation

Installation is a quick 4 steps process:, (*6)

  • Install the bundle
  • Enable the bundle
  • Create your model class
  • Configure the bundle

Step 1: Install the bundle

The preferred way to install this bundle is to rely on Composer:, (*7)

composer require spomky-labs/role-hierarchy-bundle

Step 2: Enable the bundle

Finally, enable the bundle in the kernel:, (*8)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new SpomkyLabs\RoleHierarchyBundle\SpomkyLabsRoleHierarchyBundle(),
    );
}

Step 3: Create model class

This bundle needs to persist roles to a database:, (*9)

Your first job, then, is to create a role class for your application. This class can look and act however you want: add any properties or methods you find useful., (*10)

There is just a few requirements:, (*11)

  • They must be sure that role names are unique
  • They should follow naming conventions

In the following sections, you'll see an example of how your class should look., (*12)

Your class can live inside any bundle in your application. For example, if you work at "Acme" company, then you might create a bundle called AcmeRoleBundle and place your classs in it., (*13)

This bundle is able to support Doctrine ORM, ODM, CouchDB or MongoDB. Please note that only ORM has been tested., (*14)

Doctrine ORM

If you are persisting your data via the Doctrine ORM, then your class should live in the Entity namespace of your bundle and look like this to start:, (*15)

<?php
// src/Acme/RoleBundle/Entity/Role.php

namespace Acme\RoleBundle\Entity;

use SpomkyLabs\RoleHierarchyBundle\Entity\Role as Base;
use Doctrine\ORM\Mapping as ORM;

/**
 * Role
 *
 * @ORM\Table(name="roles")
 * @ORM\Entity()
 */
class Role extends Base
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="Role")
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
     **/
    protected $parent;

    public function getId() {
        return $this->id;
    }
}

Doctrine ODM

To be written, (*16)

Couch DB

To be written, (*17)

Mongo DB

To be written, (*18)

Step 4: Configure your application

# app/config/config.yml
spomkylabs_role_hierarchy:
    role_class: "Acme\RoleBundle\Entity\Role"

If you have your own roles manager, you can use it. It just needs to implement SpomkyLabs\RoleHierarchyBundle\Model\RoleManagerInterface., (*19)

# app/config/config.yml
spomkylabs_role_hierarchy:
    ...
    role_manager: "my.custom.role.manager"

The Versions

28/11 2013
15/11 2013