[11.x] Add methods to the HTTP kernel to append middleware relative to other middleware #52897
+119
−0
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.
This PR allows for the programmatic insertion of middleware into the priority, relative to existing prioritised middleware.
Reasoning
My thought behind this is that third-party package developers can now register the priority of their middleware without requiring the user to mess with it themselves. I am currently developing a package where the priority of middleware will depend on several factors, so mostly, I need this. XD
Methods
Kernel::addToMiddlewarePriorityRelative()
This method adds middleware to the
Kernel::$middlewarePriority
property relative to other middleware. This method is protected and exists for the other two methods.Kernel::addToMiddlewarePriorityAfter()
This method adds middleware to the
Kernel::$middlewarePriority
property after existing middleware.The above adds the
ValidateSignature
middleware to the priority list after the two provided pieces of middleware, ensuring that it will run after them.This method also accepts a string and not just an array, so you can insert after a single piece of middleware.
Kernel::addToMiddlewarePriorityBefore()
This method adds middleware to the
Kernel::$middlewarePriority
property before existing middleware.The above adds the
ValidateSignature
middleware to the priority list before the two provided pieces of middleware, ensuring that it will run before them.This method also accepts a string and not just an array, so you can insert before a single piece of middleware.