Download the PHP package appsco/assertion-voter-bundle without Composer

On this page you can find all versions of the php package appsco/assertion-voter-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package assertion-voter-bundle

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.

Doctrine Orm Voter Record Provider

  1. (required) Create your VoterRecord entity

    In most cases it will look like this:

    <?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

    Set voter_record_provider in app/config/config.yml to appsco.assertion.voter_record_provider.orm

    Set voter_record_class in app/config/config.yml to your voter record class name.

    Example:

    # 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

    Set voter_record_provider in app/config/config.yml to appsco.assertion.voter_record_provider.dbal

    Example:

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

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

    You can customize each of these settings by setting container parameters:

    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.

  1. (required) Create provider service

    Create your own service which implements Appsco\AssertionVoterBundle\VoterRecordProvider\VoterRecordProviderInterface and register it within container.

  2. (required) Instruct bundle to use it

    Set voter_record_provider in app/config/config.yml to your.assertion_voter.record_provider.service_key

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.

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

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:

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.


All versions of assertion-voter-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
symfony/dependency-injection Version ~2.1
appsco/component-assertion-voter Version 1.0.0-RC1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package appsco/assertion-voter-bundle contains the following files

Loading the files please wait ....