Added factory for RouteCollection, makes subclassing of RouteCollection possible. #1175
Added factory for RouteCollection, makes subclassing of RouteCollection possible. #1175
Conversation
@@ -64,8 +63,12 @@ public function __construct(array $values = array()) | |||
|
|||
$app = $this; | |||
|
|||
$this['routes'] = function () { | |||
return new RouteCollection(); | |||
$this['routes_class'] = 'Symfony\\Component\\Routing\\RouteCollection'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this as overriding the routes_factory
would do the same. So, it's not really a good extension point.
I updated the code and added some tests to cover this new feature as you suggested @fabpot. Do you think the tests provide enough coverage? @stof, this PR does not solve my use case directly, but using it to have |
use Silex\Api\BootableProviderInterface; | ||
use Silex\Api\EventListenerProviderInterface; | ||
use Silex\Api\ControllerProviderInterface; | ||
use Silex\Provider\RoutingServiceProvider; | ||
use Silex\Provider\KernelServiceProvider; | ||
use Symfony\Component\Routing\RouteCollection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be reverted back to its original place.
@fabpot PR updated. |
6808670
to
18f253f
Compare
I squashed my commits and rebased the PR. |
Thank you @lschricke. |
… RouteCollection possible. (lschricke) This PR was merged into the 2.0.x-dev branch. Discussion ---------- Added factory for RouteCollection, makes subclassing of RouteCollection possible. Note: replaces #1174, which was targeting a wrong branch (and where I messed a bit with the commits ;)). -- The aim of this PR is to allow developpers to subclass `Symfony\Component\Routing\RouteCollection` to change some of its behavior. In most of my Silex apps, I figured I don't want the Symfony's `RouteCollection` regular behavior where if you define two routes with the same name (bad copy-paste for instance), the first route added simply gets overriden by the second. Instead, I would like to be able to throw an Exception if that happens. So I've written [a tiny subclass of RouteCollection](https://github.com/lschricke/symfony-strict-route-collection), but to be able to use it (through [a service provider like this](https://github.com/lschricke/silex-strict-route-collection-service-provider) for instance (needs to be updated for Silex 2)), I need to be able to replace `RouteCollection` by my subclass. This PR makes it possible. Thanks! :) Commits ------- 18f253f Added factory for RouteCollection, makes subclassing of RouteCollection possible.
And thank you @fabpot and all the contributors for this awesome tool! :) |
Note: replaces #1174, which was targeting a wrong branch (and where I messed a bit with the commits ;)).
The aim of this PR is to allow developpers to subclass
Symfony\Component\Routing\RouteCollection
to change some of its behavior.In most of my Silex apps, I figured I don't want the Symfony's
RouteCollection
regular behavior where if you define two routes with the same name (bad copy-paste for instance), the first route added simply gets overriden by the second. Instead, I would like to be able to throw an Exception if that happens. So I've written a tiny subclass of RouteCollection, but to be able to use it (through a service provider like this for instance (needs to be updated for Silex 2)), I need to be able to replaceRouteCollection
by my subclass. This PR makes it possible.Thanks! :)