flame-org/Modules — pull request #21 by TomasVotruba (2014-09-22 19:21:30+00:00)
Title: DecoratorExtension future compatibility for router services

1. In Nette\DI master there was recently added [DecoratorExtension](https://github.com/nette/di/commit/28fdac304b967ae43a90936069d94316ee2daca4).

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**:

```yaml
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:

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

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

```yaml
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](https://github.com/Kdyby/Events/blob/aa0e2955ef7b2e0b4f2f0044e420aba5159bf7e3/src/Kdyby/Events/DI/EventsExtension.php#L120-L123), [Zenify\DoctrineFilters](https://github.com/Zenify/DoctrineFilters/blob/fd5cceebaff4b1af4898d9444f136da05a17a85f/src/Zenify/DoctrineFilters/DI/FiltersExtension.php#L48-L55) etc.).