-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
Add the ability to append and prepend middleware priority from the application builder #53326
Add the ability to append and prepend middleware priority from the application builder #53326
Conversation
…plication builder
Can the signature be something like: $middleware->appendToPriorityList(after: $middlewareToPutTheNewMiddlewareAfter, append: $theMiddlewareToAppend);
$middleware->prependToPriorityList(before: $middlewareToPutTheNewMiddlewareBefore, prepend: $theMiddlewareToPrepend); Please mark as ready for review when the requested changes have been made. |
Hey there! I'm not sure if the parameter names match what I mentioned? |
Oh sorry, I had assumed they were just to illustrate as the names are quite long. No worries, I'll update that now. |
All done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs tests as I have tried to move my ->priority()
call to use this but the priority doesn't change.
Additionally there is an issue with using both as below.
if ($priorityAppends = $middleware->getMiddlewarePriorityAppends()) { | ||
foreach ($priorityAppends as $middleware => $after) { | ||
$kernel->addToMiddlewarePriorityAfter($after, $middleware); | ||
} | ||
} | ||
|
||
if ($priorityPrepends = $middleware->getMiddlewarePriorityPrepends()) { | ||
foreach ($priorityPrepends as $middleware => $before) { | ||
$kernel->addToMiddlewarePriorityBefore($before, $middleware); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using both prependToPriorityList()
and appendToPriorityList()
the $middleware
variable is overridden on line 274. getMiddlewarePriorityPrepends()
is then called on a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this seems to be a bug either prepending!
I suspect this is because of the bug you mentioned. I've created a PR fix at #53504 |
This is a follow-up PR for #52897 that adds two methods to the application builder, allowing for easy access to the add middleware after/before methods on the kernel.
Using the examples from the previous PR, the methods would be accessible like so:
They map as follows:
Middleware::appendToPriorityList()
->Kernel::addToMiddlewarePriorityAfter()
Middleware::prependToPriorityList()
->Kernel::addToMiddlewarePriorityBefore()