spomky-labs / role-hierarchy-bundle
Symfony2 Role Hierarchy Bundle
Installs: 828
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 3
Forks: 2
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=5.6
- doctrine/doctrine-bundle: ^1.0
- symfony/security-bundle: ^2.8|^3.0
Requires (Dev)
- behat-extension/doctrine-data-fixtures-extension: dev-master
- behat/behat: ^3.0
- behat/mink: *
- behat/mink-browserkit-driver: *
- behat/mink-extension: ^2.1
- behat/symfony2-extension: ^2.0
- doctrine/doctrine-fixtures-bundle: ^2.0
- doctrine/orm: ^2.2
- symfony/class-loader: ^2.8|^3.0
- symfony/finder: ^2.8|^3.0
- symfony/framework-bundle: ^2.8|^3.0
- symfony/validator: ^2.8|^3.0
- symfony/var-dumper: ^2.8|^3.0
- symfony/yaml: ^2.8|^3.0
This package is auto-updated.
Last update: 2022-02-01 12:32:09 UTC
README
Prerequisites
This version of the bundle requires:
- 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
.
Installation
Installation is a quick 4 steps process:
- 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:
composer require spomky-labs/role-hierarchy-bundle
##Step 2: Enable the bundle##
Finally, enable the bundle in the kernel:
<?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:
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.
There is just a few requirements:
- 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.
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.
This bundle is able to support Doctrine ORM, ODM, CouchDB or MongoDB. Please note that only ORM has been tested.
###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:
<?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
###Couch DB###
To be written
###Mongo DB###
To be written
##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
.
# app/config/config.yml spomkylabs_role_hierarchy: ... role_manager: "my.custom.role.manager"