flame-org / Modules

Nette modules on the Steroids
http://flame-org.github.io/Modules/
GNU Lesser General Public License v3.0
13 stars 7 forks source link

DecoratorExtension future compatibility for router services #21

Closed TomasVotruba closed 9 years ago

TomasVotruba commented 9 years ago

1) In Nette\DI master there was recently added DecoratorExtension.

What it does? It process services implementing certain interface or extending certain class. So you don't have to tag all router services and spam your config.neon.

This PR enables this package compatibility with DecoratorExtension:

extensions:
    decorator: Nette\DI\Extensions\DecoratorExtension

decorator:
    Flame\Modules\Application\IRouterFactory:
        tags: [flame.modules.router]

So now I just add implement IRouterFactory to router service and add my services to config.neon. Interface also enforces factory method name, which is good practice and prevents errors :+1:

services:
    - App\ModuleOne\Routing\MyRouter
    - App\ModuleTwo\Routing\FrontRouter
    - App\ModuleTwo\Routing\AdminRouter

Before this PR, you'd have to do it like this:

services:
    -
        class: App\ModuleOne\Routing\MyRouter
        tags: [flame.modules.router]
    -
        class: App\ModuleTwo\Routing\FrontRouter
        tags: [flame.modules.router]
    -
        class: App\ModuleTwo\Routing\AdminRouter
        tags: [flame.modules.router]

Which really sucks. Also you'd have to google/remember the exact string of the tag.


2) I also moved creating services to beforeCompile method, where all tag processing belongs (e.g. Kdyby\Events, Zenify\DoctrineFilters etc.).

jsifalda commented 9 years ago

Good job! Thank you. ;)

What should be added as well: (based on discussion on twitter https://twitter.com/VotrubaT/status/514332895964844032) 1) Autowire option (at the moment I exactly don't know sense of this? why does it solve the Modules lib? 2) Definitely IDecoratorProvider.