feat: scaffold routes with explicit controller imports#46
Closed
eaguad1337 wants to merge 1 commit into
Closed
Conversation
Switch the default skeleton route files from the string "WelcomeController@show" reference to importing the controller class and passing the method directly (WelcomeController.show). This is already fully supported by HTTPRoute._find_controller (the same mechanism Route.view/Route.redirect use internally), so it is a non-breaking scaffold-only change. The explicit style enables go-to-definition, autocomplete, rename refactors and import-time errors for missing controllers instead of runtime string resolution. The string "Controller@method" form remains fully supported, as do the Route.resource()/Route.api() helpers which still take a string controller.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Context
Comes out of discussion #42: the default
routes/web.pyuses the string syntax"WelcomeController@show", and adopting an explicit controller-import style was proposed.Finding
This syntax is already supported by the framework — no core changes are required.
HTTPRoute._find_controller(src/masonite/routes/HTTPRoute.py:187-202) already resolves aClass.methodreference passed directly via__qualname__/__module__. It is in fact the same mechanismRoute.view/Route.redirectuse internally (ViewController.show,RedirectController.redirect).So this PR is a scaffold-only, non-breaking change.
Change
Updates the skeleton route files to import the controller class and pass the method directly:
(The commented example in
api.pyis updated to match.)Why
SyntaxErrorwhen the request hits the route.controllers_locations.Compatibility
"Controller@method"form remains fully supported; existing apps are unaffected.Route.resource()/Route.api()helpers still take a string controller. Standardizing those to the class style would be a separate follow-up (the only point of inconsistency with this convention).Closes #42.