Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📚 Description
I think that since the Router became instantiable and it was possible to be configured multiple times, our use of the Router API became somewhat more complex. On the one hand, you could create, configure, and execute the Router statically only using
Router::configure()
, and on the other hand, you could create an instance, configure, and execute it by consecutively callingRouter::create()
,$router->addRoutes()
, and$router->run()
.All of this seems to me to add an extra layer of complexity that could be resolved simply by offering a new non-static method of operation. By doing less for the user and following the KISS principle, the fewer public methods we expose, the simpler it will be for developers to use our API. Therefore, it would be easier to use, although this would force anyone who wants to use the "old static method" to instantiate a router, configure it, and execute it.
In addition, the method for configuring the router instance is called
addRoutes()
, a name that I don't think is entirely appropriate, since it not only serves to add Routes but also Handlers and Dependencies, which I believe makes it even more difficult to use.This PR is just a proposal for how I think everything could be simplified. Feel free to open up a debate, propose alternatives, make changes...