2017 © Pedro Peláez
 

symfony-bundle role-provider-orm-bundle

The DCSRoleProviderORMBundle provides the management of user roles using Doctrine ORM

image

dcs/role-provider-orm-bundle

The DCSRoleProviderORMBundle provides the management of user roles using Doctrine ORM

  • Saturday, December 31, 2016
  • by damianociarla
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Build Status Coverage Status, (*1)

DCSRoleProviderORMBundle

This bundle provides the provider implementation for DCSRoleCoreBundle. This provider is built in on Doctrine ORM and performs a mapping of the Role class., (*2)

To manage the roles through your User class this bundle provides the UserRoleCollection trait., (*3)

Installation

Prerequisites

This bundle requires DCSRoleCoreBundle., (*4)

Require the bundle

Run the following command:, (*5)

$ composer require dcs/role-provider-orm-bundle "~1.0@dev"

Composer will install the bundle to your project's vendor/dcs/role-provider-orm-bundle directory., (*6)

Enable the bundle

Enable the bundle in the kernel:, (*7)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new DCS\Role\Provider\ORMBundle\DCSRoleProviderORMBundle(),
        // ...
    );
}

Create your Role class

You must provide a concrete Role class. You must extend the abstract model DCS\Role\Provider\ORMBundle\Model\Role and create the appropriate mapping., (*8)

Annotations
<?php
// src/AcmeBundle/Entity/Role.php

namespace AcmeBundle\Entity;

use DCS\Role\Provider\ORMBundle\Model\Role as RoleBase;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="role")
 */
class Role extends RoleBase
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
}
Yaml
# src/AcmeBundle/Resources/config/doctrine/Role.orm.yml
AcmeBundle\Entity\Role:
    type:  entity
    table: role
    id:
        id:
            type: integer
            generator:
                strategy: AUTO
Xml
<?xml version="1.0" encoding="utf-8"?>
<!-- src/AcmeBundle/Resources/config/doctrine/Role.orm.xml -->
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="AcmeBundle\Entity\Role" table="role">
        <id name="id" type="integer" column="id">
            <generator strategy="AUTO"/>
        </id>
    </entity>
</doctrine-mapping>

Update your User class

In this step you'll need to update your User class to make it compatible with the Role class created in the previous step. For convenience, we will use the UserRoleCollection trait., (*9)

Annotations
<?php
// src/AcmeBundle/Entity/User.php

namespace AcmeBundle\Entity;

use DCS\User\CoreBundle\Model\User as UserBase;
use DCS\Role\Provider\ORMBundle\Model\UserRoleCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * ... your mapping entity
 */
class User extends UserBase
{
    use UserRoleCollection;

    //... other mapping fields

    /**
     * @ORM\ManyToMany(targetEntity="AcmeBundle\Entity\Role")
     * @ORM\JoinTable(name="user_role",
     *   joinColumns={
     *     @ORM\JoinColumn(name="user_id", referencedColumnName="id")
     *   },
     *   inverseJoinColumns={
     *     @ORM\JoinColumn(name="role_id", referencedColumnName="id")
     *   }
     * )
     */
    protected $roles;
}
Yaml
# src/AcmeBundle/Resources/config/doctrine/User.orm.yml
AcmeBundle\Entity\User:
    //... your mapping entity
    manyToMany:
        roles:
            targetEntity: AcmeBundle\Entity\Role
            joinTable:
                name: user_role
                joinColumns:
                    user_id:
                        referencedColumnName: id
                inverseJoinColumns:
                    role_id:
                        referencedColumnName: id
Xml
<?xml version="1.0" encoding="utf-8"?>
<!-- src/AcmeBundle/Resources/config/doctrine/User.orm.xml -->
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="AcmeBundle\Entity\User">
        <!-- your mapping entity -->
        <many-to-many field="roles" target-entity="AcmeBundle\Entity\Role">
            <join-table name="user_role">
                <join-columns>
                    <join-column name="user_id" referenced-column-name="id" />
                </join-columns>
                <inverse-join-columns>
                    <join-column name="role_id" referenced-column-name="id" />
                </inverse-join-columns>
            </join-table>
        </many-to-many>
    </entity>
</doctrine-mapping>

Configure

Now that you have properly enabled this bundle, the next step is to configure it to work with the specific needs of your application., (*10)

Add the following configuration to your config.yml., (*11)

dcs_role_provider_orm:
    model_class: AcmeBundle\Entity\Role

The following lines provide the configuration for the DCSRoleCoreBundle., (*12)

dcs_role_core:
    provider: dcs_role.provider.orm

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker., (*13)

The Versions

31/12 2016

dev-master

9999999-dev

The DCSRoleProviderORMBundle provides the management of user roles using Doctrine ORM

  Sources   Download

MIT

The Requires

 

The Development Requires

orm user doctrine symfony role roleprovider