northwoods / broker Goto Github PK
View Code? Open in Web Editor NEWDead simple PSR-15 middleware dispatcher
License: MIT License
Dead simple PSR-15 middleware dispatcher
License: MIT License
Hi!
Looking or a dispatcher that is compatible with PHP ^5.4 | ^7.0. Could not find the min required version here. I see that it was bult on PHP 7 (failing, by the way, on minimal dependencies, which can be remedied by explicitly depending on container-interop/container-interop:^1.2
; see also this comment), but can't tell if will run with PHP 5.
Would it be possible to add some indication of minimal requirements?
The documentation in the readme states:
When a container is provided middleware can be added by class name
But this is only true if the keys of middleware services are their class names. In any other case, this is not true. I found this to be very misleading, as it lead me to wonder about how middleware is resolved from the container by class name. Instead, it seems more clear to explain that the middleware will be retrieved from the container by key.
Upon reading the readme, I noticed that one way to dispatch the middleware pipe is with Broker::handle()
. Given that a common use of handlers is as middleware dispatchers, shouldn't Broker
implement RequestHandlerInterface
istead of MiddlewareInterface
? This would look great to the consuming code, as the entry point would just need to do the same thing it would do if it were not using Broker:
/* @var $handler Northwoods\Broker\Broker /*
$handler->handle($request);
Given that Broker would probably be the top-most item of the stack that processes a request, it would make more sense for it to be a handler, rather than middleware, IMO.
I will happily implement this and send a pull request, if you agree with the idea.
What do you think about something like this?
$broker->paths([
'/foo' => $myMiddlewareStack,
'/bar' => MyMiddleware::class,
'/baz' => 'baz.middleware.stack'
]);
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.