2017 © Pedro Peláez
 

symfony-bundle efficient-vote-bundle

Provide a system to enhance performances of the security by voters

image

kinulab/efficient-vote-bundle

Provide a system to enhance performances of the security by voters

  • Tuesday, February 27, 2018
  • by nykopol
  • Repository
  • 1 Watchers
  • 3 Stars
  • 1,641 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 4 % Grown

The README.md

Efficient Vote Bundle

With Symfony you can install access management either with ACLs or with voters. ACLs are hard to implements and voters have performances issues. This bundle provides a way to enjoy the simplicity of voters without the drawback of performances., (*1)

Backgroup

The performance issue of voters comes from the AccessDecisionManager service. His role is to ask every voter to know if the current user is allowed to perform a given action (e.g. ROLE_SUPER_ADMIN). The problem is that this service is not aware that most of the voters will abstain as they don't support the attribute., (*2)

So, if your application has 10 voters and your template uses 10 times the is_granted() function, it makes 100 calls. If your application grows, this will become a bottleneck., (*3)

To solve that, this bundle overwrites the default AccessDecisionManager service. With the new service, you can register your voters and specify which attributes are supported. The access decision manager will so not call your voter if he's not competent for the attribute., (*4)

Installation

composer require kinulab/efficient-vote-bundle

Then add in you app/config/AppKernel.php :, (*5)

    public function registerBundles()
    {
        $bundles = [
            // [...]
            new Kinulab\EfficientVoteBundle\KinulabEfficientVoteBundle(),
        ];

Usage

The new access decision manager will assume that you organize your voter by types and by domains., (*6)

Your must then name your roles with this forms:, (*7)

ROLE _ HOUSE _ OPEN_DOOR
|__|   |___|   |_______|
type   domain  attribute

Your voters class remain exaclty like the standards symfony voters. The only difference is on the registration of your voter service., (*8)

With a standard vorter, your service is registered like that:, (*9)

# app/config/services.yml
services:
    app.host_voter:
        class: AppBundle\Security\hostVoter
        # small performance boost
        public: false
        tags:
            - { name: security.voter }

With this bundle you should now register your service like that :, (*10)

# app/config/services.yml
services:
    app.host_voter:
        class: AppBundle\Security\hostVoter
        # small performance boost
        public: false
        tags:
            # big performance boost
            - { name: security.efficient_voter, type: ROLE, domain: HOUSE }

With this configuration, the voter above, will be called only for the ROLE_HOUSE_* attributes., (*11)

Note

The new access decision manager remains compatible with the original. So if you have some voters that are registered the old way, they will still work as expected (but called tons of time)., (*12)

The Versions

27/02 2018

dev-master

9999999-dev

Provide a system to enhance performances of the security by voters

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan DESMYTER

27/02 2018

0.2.1

0.2.1.0

Provide a system to enhance performances of the security by voters

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan DESMYTER

27/02 2018

0.2.0

0.2.0.0

Provide a system to enhance performances of the security by voters

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan DESMYTER

27/02 2018

dev-issue_1

dev-issue_1

Provide a system to enhance performances of the security by voters

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan DESMYTER

23/11 2017

0.1.1

0.1.1.0

Provide a system to enhance performances of the security by voters

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan DESMYTER

21/11 2017

0.1.0

0.1.0.0

Provide a system to enhance performances of the security by voters

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johan DESMYTER