dunglas / DunglasActionBundle

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

[question] Different tags, same interface requirement #48

Closed akomm closed 8 years ago

akomm commented 8 years ago

Assume you use both doctrine ORM and ODB in your project.

You have subscribers: AppBundle\Subscribers\{ODM,ORM}

ODM subscribers need a service tag doctrine_mongodb.odm.event_subscriber ORM subscribersneed a service tag doctrine.event_subscriber

Both have same interface requirement: Doctrine\Common\EventSubscriber

So you can not differentiate between them by interface.

What do you think is better:

  1. create interface AppBundle\Subscriber\OrmSubscriberInterface extends Doctrine\Common\EventSubscriber and interface AppBundle\Subscriber\OdmSubscriberInterface extends Doctrine\Common\EventSubscriber then config:

dunglas_action:
  tags:
    AppBundle\Subscriber\OdmSubscriberInterface:
      - ''doctrine_mongodb.odm.event_subscriber"
    AppBundle\Subscriber\OrmSubscriberInterface:
      - "doctrine.event_subscriber"

or 2: An option inside the "tags" config to narrow down to a directory?

  1. involves empty interfaces as markers, but is simple and does not need to be implemented.
  2. As far as I know is not possible via config and would need to be implementation. Might blow up things up unnecessary.
GuilhemN commented 8 years ago

Your first solution seems better to me as this isn't usual and would complexify the bundle.

dunglas commented 8 years ago

I agree with @Ener-Getick, solution 1 looks even cleaner from an OOP point of view. Closing for now.