Relay: A PSR-7 Middleware Dispatcher
UPDATE (2015-06-09): Due to a conflict with the "pipeline" design pattern name, which this project does not implement, the project name has been changed from Pipeline to Relay. Links and naming have been updated inline, with the original text block quoted beneath.
In a fit of inspiration over the weekend, I extracted the middleware dispatcher from the Radar ADR core into its own standalone library: Relay. If you need to execute a queue of middleware, Relay is for you.
Relay uses a common PSR-7 middleware signature: function ($request, $response, $next)
and return $response
. That is what Slim 3 uses, along with Stratigility and Radar, and is modeled on Sencha Connect. Any callable/invokable with that signature will work with Relay.
As a standalone library, Relay is framework-independent, so you can use it anywhere. You could even build your own framework around it, picking a dotenv-loader of your choice, a DI container of your choice, and a middleware queue of your choice.
Speaking of DI containers, Relay is also container-independent. You can use any dependency-injection system you like to build your middleware queue and pass it to Relay. All you need to do is pass in a callable that converts each queue entry to an object or callable. Try it with PHP-DI, Pimple, Auryn, or even Aura.Di.
I have converted Radar to use Relay at its core, and soon I'll be extracting two of the basic Radar middleware classes to standalone packages. When I do, they'll be listed on the Relay wiki.
ORIGINAL RELEASE:
In a fit of inspiration over the weekend, I extracted the middleware dispatcher from the Radar ADR core into its own standalone library: Pipeline. If you need to execute a queue of middleware, Pipeline is for you.
Pipeline uses a common PSR-7 middleware signature:
function ($request, $response, $next)
andreturn $response
. That is what Slim 3 uses, along with Stratigility and Radar, and is modeled on Sencha Connect. Any callable/invokable with that signature will work with Pipeline.As a standalone library, Pipeline is framework-independent, so you can use it anywhere. You could even build your own framework around it, picking a dotenv-loader of your choice, a DI container of your choice, and a middleware queue of your choice.
Speaking of DI containers, Pipeline is also container-independent. You can use any dependency-injection system you like to build your middleware queue and pass it to Pipeline. All you need to do is pass in a callable that converts each queue entry to an object or callable. Try it with PHP-DI, Pimple, Auryn, or even Aura.Di.
I have converted Radar to use Pipeline at its core, and soon I'll be extracting two of the basic Radar middleware classes to standalone packages. When I do, they'll be listed on the Pipeline wiki.
Read the Reddit discussion about this post here.