[5.2] Reverse a breaking addition in Route.php #12991
Merged
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.
In an earlier PR #12899, controller routes were included in the
Route:middleware()
method output by callingControllerDispatcher
, this had two effects:ControllerDispatcher::callWithinStack()
when the controller is actually being dispatched and another inRouter::runRouteWithinStack()
while the Router is dispatching the request to the route.ControllerDispatcher
is instantiating the controller, some of this code is considered protected by a middleware registered inroutes.php
.For example a code inside the controller constructor that logs a user's presence inside the dashboard area, this code will be executed although the controller is protected under the
auth
controller for example, orauth.type.admin
Also calls to
Request::user()
&&Auth::user()
will return null if the user is not logged in, although the developer added theauth
middleware to this controller inside the routes file, this will call a PHP error when Controller dispatches is called instead of executing theauth
middleware and redirect the user to the log in screen.Terminable middlewares are useful, however I say we keep the old behaviour of firing them only when registered otherwhere than the controller for 5.2 in order not to break things.
And I suggest in 5.3 we remove the
Controller::middleware()
method and make people use a static method for example that we can run from outside to collect the middlewares without executing the constructor code.And since we will be already collecting controller middlewares data before firing the controller actions, we won't need to read the controller routes from inside the controller itself.