-
Notifications
You must be signed in to change notification settings - Fork 1
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
Proposal: Mapping path prefixes to middleware stacks #6
Comments
A little bit of background: If it had this functionality, I would gladly use this library in Flarum in order to use PSR-15 middleware. We're currently using Zend's Stratigility, but their PSR-15-compatible version does not support PHP 7.0, which is - currently - still a requirement on our side. |
Would adding this functionality introduce new dependencies? I like the idea of it. For whatever it's worth, the functionality is already possible by doing something like this: $broker->when($this->matchesPath('/foo'), MyMiddleware::class); Assuming that: private function matchesPath(string $path): callable
{
return static function (RequestInterface $request) use ($path): bool {
return strpos($request->getUri()->getPath(), $path) === 0;
};
} |
I would implement it without external dependencies. Stratigility additionally strips out the path prefix from the request - which is very useful because the middleware does not need to know about the prefix. So just @shadowhand Is that a "go ahead" then? 😀 |
@franzliedke sure, I'd definitely consider a PR. Seems like it will be reasonable. |
Little status update: |
Closing, see discussion on #7 |
I will happily implement this and send a pull request, if you agree with the idea.
What do you think about something like this?
Array values can be middleware, or strings which would then be lazily resolved from the container, whenever a request with this prefix arrives.
This method would have to take care of stripping the path prefix from the request object.
The text was updated successfully, but these errors were encountered: