symfony/symfony — pull request #8551 by xphere (2013-07-23 21:59:26+00:00)
Title: [Routing] Allow easy extension of YamlFileLoader

| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | N/A
| License | MIT
| Doc PR | N/A

I often found myself extending `YamlFileLoader` to add custom routing options, and I think it's quite hard to avoid duplicating the whole class. Validation of routes is a must, and I'd like to extend the default one with more keys, but this can't be done because declaration is `private static` and static binding is used. I think it would be nice to have an easy way to extend from this class.

Some solutions come to mind:
- Change `$availableKeys` visibility to `protected` and use late static binding instead of `self::$availableKeys`.
This way is easier to replace with new keys, but harder to add to current ones.
- Extract keys to a protected method, say `getAvailableKeys`.
Allows for easy replacement and extension, by calling `parent::getAvailableKeys` and mix with the new ones.
- Create a `Symfony/Config` object in a protected method, and let derived classes to extend it.
This brings even more power (validation and conversion) but couples `Routing` to `Config` components for a little profit.

I attach the code for the second solution (extraction to protected method).
This is an easy patch, but I would love to hear some opinions in the subject.