Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
RoutingExtension: added support for custom single-route classes. #162
With this, complex "drop-in replacement" routers can be made using existing declaration for RoutingExtension.
Now, when the 'routing.router' is replaced by other class that depends e.g. on a translator, its children remain to be Nette*\Route that does not know what to do with that translator. You cannot set filters to $metadata in config.neon, so you have to replace routes with class that does it inside itself.
If my PR accepted, there is possible to simply override addRoute() where child can get its dependencies - not even for translation but e. g. for DB filtering, etc. This solution keeps freedom to declare routes both in bootstrap and config.neon. Otherwise, configuration for RoutingExtension could not be used in this case and everything would have to be done in the bootstrap.php.
I do agree. After your suggestion I've tried to find some better solution and I think I've found one.
In many cases (even in Nette and my project) RouteList and Route will be located in the same namespace. So, it would be sufficient to create routes from class Route located in the same namespace the RouteList belongs to. It not only solves my problem but also it allows me to leave my config.neon without any changes. To make it even more useful, I have added possibility to change child route's class totally by parameter routing.routeClass.
This solution has, though, one limitation. It cannot pass dependencies via constructor to child routes. These have to be set later by calling e.g. Route::setTranslator(). But this is not problem for functionality.