Our services file repeats every class name three times. Once as the id, once as the class, and again in the arguments of every service that needs it. Add a constructor parameter, edit YAML, clear cache, repeat. Symfony 3.3 lands in May and promises to delete most of that file:
services:
_defaults:
autowire: true
autoconfigure: true
AppBundle\:
resource: '../../src/AppBundle/*'
Autowiring and autoconfiguration on by default, the whole source folder registered in five lines. I have mixed feelings. Sorted, they look like this.
The good part is obvious. What we do by hand today is typing. With autowiring the type-hint is the configuration. The constructor was already the honest list of dependencies. Now the container reads it.
The uncomfortable part. Today, when I ask “where does this mailer come from”, the answer is a line in a file. In May the answer is “from the type-hint, resolved by the container at compile time”. Correct, and nowhere to look. Interfaces make it sharper. Two implementations of one interface is an ambiguity, and you resolve it with an alias, which is explicit config again. So the explicit config did not disappear. It shrank to the places where a decision exists.
Maybe that is the right way to see it. Wiring with only one possible answer should be automated, because writing it by hand adds no information. Wiring that is a choice, which of two mailers, must stay written down. Config should be a list of decisions, not an inventory.
My plan is to turn it on for new code and leave the old definitions alone. I know myself: if I start converting the old file, I will spend a week on it and call it refactoring.