2017 © Pedro Peláez
 

symfony-bundle assertion-voter-bundle

Assertion Voter Bundle

image

appsco/assertion-voter-bundle

Assertion Voter Bundle

  • Friday, May 23, 2014
  • by i3or1s
  • Repository
  • 4 Watchers
  • 0 Stars
  • 98 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 1 % Grown

The README.md

Assertion Voter Bundle

Usage

Register bundle in kernel

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Appsco\AssertionVoterBundle\AppscoAssertionVoterBundle(),
        );

        // ...
    }
}

Configure

# app/config/config.yml

appsco_assertion_voter:
    voter_record_provider: appsco.assertion.voter_record_provider.orm # Default Doctrine ORM voter record provider
    voter_factory: appsco.assertion.voter_factory.simple

Use

// Controller

public function fooAction()
{
    // Fetch assertion information from your service
    $info = $this->get('your_info_provider')->getInfo();

    // Resolve roles
    $roles = $this->get('appsco.assertion.role_resolver')->resolve($info);
}

Persistence layer integration

Bundle can be integrated with any persistence layer by implementing your own VoterRecordProviderInterface or by using one already provided in the bundle., (*1)

Doctrine Orm Voter Record Provider

  1. (required) Create your VoterRecord entity, (*2)

    In most cases it will look like this:, (*3)

    <?php
    
    namespace Acme\YourBundle\Entity;
    
    use Appsco\AssertionVoterBundle\Entity\VoterRecord as BaseVoterRecord;
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * @ORM\Entity
     */
    class VoterRecord extends BaseVoterRecord
    {
        /**
         * @ORM\Id
         * @ORM\GeneratedValue
         * @ORM\Column(type="integer")
         * @var int
         */
        private $id;
    
        /**
         * @return int
         */
        public function getId()
        {
            return $this->id;
        }
    }
  2. (required) Instruct bundle to use it, (*4)

    Set voter_record_provider in app/config/config.yml to appsco.assertion.voter_record_provider.orm, (*5)

    Set voter_record_class in app/config/config.yml to your voter record class name., (*6)

    Example:, (*7)

    # app/config/config.yml
    appsco_assertion_voter:
        voter_record_provider: appsco.assertion.voter_record_provider.orm
        voter_record_class: Acme\YourBundle\Entity\VoterRecord

Doctrine Dbal Voter Record Provider

  1. (required) Instruct bundle to use it, (*8)

    Set voter_record_provider in app/config/config.yml to appsco.assertion.voter_record_provider.dbal, (*9)

    Example:, (*10)

    # app/config/config.yml
    appsco_assertion_voter:
        voter_record_provider: appsco.assertion.voter_record_provider.dbal
  2. (optional) Customize table name and fields, (*11)

    By default it will try to fetch voter records from VoterRecord table and read the following columns: issuer, attribute, value, role, (*12)

    You can customize each of these settings by setting container parameters:, (*13)

    Table name      : appsco.assertion.voter_record_provider.dbal.table_name
    Issuer column   : appsco.assertion.voter_record_provider.dbal.issuer_column
    Attribute column: appsco.assertion.voter_record_provider.dbal.attribute_column
    Value column    : appsco.assertion.voter_record_provider.dbal.value_column
    Role column     : appsco.assertion.voter_record_provider.dbal.role_column: role

Using custom Voter Record Provider

If you're using other persistence layer you can easily integrate bundle with it., (*14)

  1. (required) Create provider service, (*15)

    Create your own service which implements Appsco\AssertionVoterBundle\VoterRecordProvider\VoterRecordProviderInterface and register it within container., (*16)

  2. (required) Instruct bundle to use it, (*17)

    Set voter_record_provider in app/config/config.yml to your.assertion_voter.record_provider.service_key, (*18)

Decision Makers

Sometimes, you might want to do more complex decision making, eg. disable editing roles if user has no ROLE_ENABLED etc. To do this you need more than just a set of simple vote records., (*19)

You need to implement your own decision maker. Make a service which implements BWC\Component\AssertionVoter\DecisionMakerInterface and tag it:, (*20)

my.custom.assertion.decision_maker:
    class: My\Custom\DecisionMakerServiceClass
    tags:
        - { name: appsco.assertion.decision_maker, alias: my_decision_maker }

And now you can run assertions against it:, (*21)

public function fooAction()
{
    // Fetch assertion information from your service
    $info = $this->get('your_info_provider')->getInfo();

    // Resolve roles
    $roles = $this->get('appsco.assertion.role_resolver')->resolve($info, 'my_decision_maker');
}

Note second parameter in RoleResolver::resolve method. It must match alias from appsco.assertion.decision_maker class., (*22)

The Versions

23/05 2014

dev-master

9999999-dev

Assertion Voter Bundle

  Sources   Download

The Requires

 

assertion voter

23/05 2014

1.0.1

1.0.1.0

Assertion Voter Bundle

  Sources   Download

The Requires

 

assertion voter

08/05 2014

1.0.1-RC1

1.0.1.0-RC1

Assertion Voter Bundle

  Sources   Download

The Requires

 

assertion voter

06/05 2014

1.0.0-RC1

1.0.0.0-RC1

Assertion Voter Bundle

  Sources   Download

The Requires

 

assertion voter