Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] 4.x Refactor Routing #2604

wants to merge 13 commits into from


None yet
2 participants
Copy link

commented Mar 4, 2019

This is a draft proposal to refactor all routing components as per issue #2583.

The proposed changes introduce the following interfaces:

  • RouteCollectorInterface: Collects all routes and groups, handles cache file
  • RouteCollectorProxyInterface: This interface is what the App components extends and also what is being passed into RouteGroup. We will not be exposing all of App's methods when instantiating a RouteGroup instead this proxy interface handles communication with the RouteCollector
  • RouteInterface stays the same, minor change is that we have gotten rid of Routable all together
  • RouteGroupInterface this interface now has a collectRoutes() method which helps us get rid of the old RouteGroup::__invoke(), Router::pushGroup() and Router::popGroup() methods. RouteCollectorProxy has the ability to have a base path which will append it to all the patterns being passed via the proxy methods get(), put(), post(), etc. while collecting the routes from inside the RouteGroup's callable
  • RouteResolverInterface this component is very simple and its only concerns are to create the FastRoute dispatcher, dispatch the ServerRequestInterface to it and return the computed RoutingResults via the RouteResolverInterface::computeRoutingResults() method. This interface also has the responsibility to resolve the appropriate route communicating with RouteCollector to achieve that. RoutingMiddleware uses this resolver to perform the routing.

Deprecated Components/Methods

  • Router and RouterInterface are now gone since they've been effectively separated
  • Routable does not exist anymore as it has been merged into Route since it is the only component that was using those methods
  • RouteGroup does not hold a $pattern variable anymore as it is unnecessary due to the state of the pattern residing inside RouteCollectorProxy when collecting the inner routes of a group
  • Route::finalize() does not exist anymore, it has effectively been merged with Route::prepare()
  • RouteDispatcher has been renamed to RouteRunner since that's all it does, it calls Route::run()

New Namespace Folder
New namespace folder called Routing which has all of the routing components.

This PR will be separated into smaller ones

  • Decouple RouteGroup & Route from Routable - #2612 Merged
  • Decouple Router into RouteCollector and RouteResolver - #2622 Merged
  • Add Route::setInvocationStrategy() to RouteInterface - #2634 Merged
  • Add RouteCollector::fullUrlFor() as per #2493 - #2638 Merged
  • Introduce DispatcherInterface to decouple from FastRoute Dispatcher - #2639 Merged
  • Introduce RouteParserInterface to decouple from FastRoute RouteParser - #2640 Merged
  • Introduce RouteCollectorProxy - #2641 & #2642 Merged

@l0gicgate l0gicgate added the Slim 4 label Mar 4, 2019

@l0gicgate l0gicgate added this to the 4.0 milestone Mar 4, 2019

@l0gicgate l0gicgate self-assigned this Mar 4, 2019

@l0gicgate l0gicgate requested a review from akrabat Mar 4, 2019


This comment has been minimized.

Copy link
Contributor Author

commented Mar 4, 2019

@bnf I would like your input on this when you get a minute. Thank you!

@l0gicgate l0gicgate changed the title [DRAFT] 4.x - Refactor Routing [DRAFT] 4.x Refactor Routing Mar 4, 2019


This comment has been minimized.

Copy link

commented Mar 10, 2019

This is in danger of being too big. Can we pull out some bits into their own PRs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.