-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Allow specifying middlewares at the controller level. #15558
Conversation
5a68500
to
33e6953
Compare
* @return void | ||
* @psalm-var array{?only: string|array, ?except: string|array} | ||
*/ | ||
public function middleware($middleware, array $options = []) |
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.
Should this method raise an exception if it is called after middleware have already been applied? It would be frustrating to use this method in a beforeRender
and then think that Cake is 'broken' when you're using it wrong.
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.
Could be start with just documenting the fact that middlewares must be set from initialize()
only?
I don't think we would be able to check if the middleware queue was already created without adding a new property.
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.
Yeah we would need another property to track whether or not middleware could be added.
While we can setup route based middlewares at times setting them can be a bit cumbersome. If for e.g. you want a middleware to run for just one action you would have to setup an extra route for it. Middlewares for controllers provides a good conveninece and also replacing some components with middlewares.
33e6953
to
32a5ab3
Compare
Can this be merged? |
While we can setup route based middlewares at times setting them can be
a bit cumbersome. If for e.g. you want a middleware to run for just one
action you would have to setup an extra route for it.
Middlewares for controllers provides a good convenience and also allow replacing
some components with middlewares.
P. S. Laravel allows setting up middleware for controller in a similar way.