dispatch
dispatch copied to clipboard
before()
Hi, quick question, what is the alternative to the before() method in the latest release?
sorry, there's still no replacement for before()
in the current version. this is being worked on, though it might not be implemented the same way as we had it before.
Hey @noodlehaus, any update on this? getting to a point in an application where a before()
method would really help authenticate a series of API endpoints I'm writing.
Sorry I never got back to this. I am working on bringing back the functionality as apply($path, ...$handlers)
, like the following:
# apply auth() and loadBook() under this route
apply('/record/:id', auth(...), loadBook(...));
# auth() and loadBook() should have been executed
route('GET', '/record/:id/edit, showEditBookForm(...));
This would require a way to forward values from the middleware to the next handlers, for cases where the middleware is used for preparing the context for the final handlers. For ones that divert handling, this is not an issue.
Another approach might be to just allow multiple callables in the route()
method like so:
route('GET', '/admin', auth(...), showDashboard(...));
Looking into this finally.
Closing this. Features already in #90. Just verifying the minimum required PHP version for these (8+).