dunglas / DunglasActionBundle

Symfony controllers, redesigned
https://dunglas.fr/2016/01/dunglasactionbundle-symfony-controllers-redesigned/
MIT License
256 stars 14 forks source link

Additional service options #54

Open akomm opened 8 years ago

akomm commented 8 years ago

I want to also add public: false property to all Voters. I have the following entry:

dunglas_action:
  directories:
    - '../src/AppBundle/Security/Voter'
  tags:
    Symfony\Component\Security\Core\Authorization\Voter\VoterInterface:
      - 'security.voter'

I would not like to define all the Voter services, just because I want them all to be private. Do you think a config key for options (excluding autowire) would be a good solution for this?

dunglas_action:
  options:
    # or by directory?
    Symfony\Component\Security\Core\Authorization\Voter\VoterInterface:
      public: false
GuilhemN commented 8 years ago

:+1: What about:

dunglas_action:
    must_be_public:
        - Symfony\Component\Security\Core\Authorization\Voter\VoterInterface

and make all the others private (or maybe also add an option for that)?

IMO every service should be able to be private but it was refused in the core.

dunglas commented 8 years ago

Why not using a user-land compiler pass for that? You can do a simple check on the namespace.

GuilhemN commented 8 years ago

@dunglas that's indeed already possible but it complexify the installation of the bundle. Including it here would also permit to follow the core autowiring behavior (private by default).

akomm commented 8 years ago

:+1: private by default and public by option sounds good.

theofidry commented 8 years ago

👎 for private services by default, I would rather just follow the Symfony convention here. As services are not private by default (although there is an issue to change that, https://github.com/symfony/symfony/issues/20048), I don't think it should be done here.

Instead of just having tags, why not having services instead to which we can append things to the service definition, i.e. tags and public properties?

dunglas_action:
    services:
        'Symfony\Component\Security\Core\Authorization\Voter\VoterInterface':
            tags: [ name: 'mytag' ]
            public: false

EDIT: actually isn't it already doable by overriding the service definition?


services:
    'Symfony\Component\Security\Core\Authorization\Voter\VoterInterface':
        tags: [ name: 'mytag' ]
        public: false
magarzon commented 7 years ago

I have created a CompilerPass for another "service option" that resolves a "problem" with the "autotag" feature: if you need to set a priority for a service, then you can't use autotag.

I have implemented an interface PrioritizedInterface with a method getPriority, and the CompilerPass searches for services with this interface and set the priority calling this method.

That way I can use autotag and priority.

If you think this is of interest for this bundle, I can make a PR