refactor(router): extract Router into RouteBuilder, RouteMatcher, and RouteDispatcher#376
Merged
Merged
Conversation
… RouteDispatcher Extract the 1632-line Router class into three focused classes: - RouteBuilder: route construction, option validation, sub-route grouping - RouteMatcher: URI resolution and matching against registered routes - RouteDispatcher: dispatching matched routes to resources, middleware execution Router retains its full public static API and delegates internally, ensuring full backward compatibility. Refs #375
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #376 +/- ##
============================================
+ Coverage 79.26% 83.41% +4.14%
+ Complexity 3251 2523 -728
============================================
Files 105 86 -19
Lines 9642 7789 -1853
============================================
- Hits 7643 6497 -1146
+ Misses 1999 1292 -707
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Extract the 1632-line
Router.phpinto three focused classes:RouteBuilder,RouteMatcher, andRouteDispatcher, while keeping the public static API fully backward compatible.Motivation
The Router class had grown to 1632 lines mixing route construction, URI matching, and resource dispatching concerns. This makes it hard to maintain and test individual responsibilities. Refs #375.
Changes
RouteBuilderclass: route construction, option validation, sub-route grouping, middleware group assignmentRouteMatcherclass: URI resolution and matching against registered static/variable routesRouteDispatcherclass: dispatching matched routes to resources (closures, classes, files), middleware execution, redirect handlingRouterto delegate to the three new classes while retaining its full public static APIHow to Test / Verify
All existing unit tests pass without modification:
Breaking Changes and Migration Steps
None. The public API of
Routeris unchanged. All static methods (addRoute,api,closure,page,route,routes, etc.) work identically.Checklist
composer fix-cs)Related issues
Refs #375