The point of all this is that maybe YAML should be dropped altogether in favor of PHP definitions.
YAML is less verbose, but since PHP 5.4 (short arrays) and 5.5 (short class names) it's even.
Advantages of PHP:
- autocompletion
- refactoring support
- click to go to a class
- definitions using callbacks
- use of class constants
- can write any PHP code (instead of a DSL like the new Symfony component)
- use of helpers to help define dependencies (-> autocompletion and guidance)
- no need to separate values and class definitions (in YAML, we have to since a class definitions is an array)
This is a long list…
Below is a proposition on how it could be implemented for PHP-DI 4.0. And down below would be the same config file written in YAML, for comparison purposes.
Problem: finding good class and method names for the helper methods (Definition::object
…) so that they don't "pollute" too much the definitions. The shorter the better…
Suggestions:
Definition
Entry
Other problem: the new API makes doesn't allow to define "lazy" dependencies. Should it rather be something more simple (like configuring everything to be lazy, or configuring it at class level)?