KO
|
EN
gitlite — search
Search
#javascript
#python
#hacktoberfest
#react
#ai
#typescript
#llm
#go
#golang
#android
#machine-learning
#rust
#deep-learning
#linux
middleware
★ 17
Open GitHub ↗
:whale: A PSR15 middleware dispatcher
Download README (.md)
Explore Similar Repositories
answers-of-my-life
:
模仿纸质版答案之书做的web版的答案之书
programming-notes
:
for Python, data science, and C++
CO2projections
:
No description available.
CDs
:
The OpenMath Content Dictionaries
WPImgOptimizer
:
WordPress image optimisation development workflow.
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
middleware
?
Download (.md)
# Middleware Dispatcher [](https://travis-ci.org/slince/middleware) [](https://codecov.io/github/slince/middleware) [](https://packagist.org/packages/slince/middleware) [](https://scrutinizer-ci.com/g/slince/middleware/?branch=master) The package is a flexible PSR-15 middleware dispatcher for PSR-7 request message that help to create middlewares and dispatch. ## Installation Install via composer ```bash composer require slince/middleware ``` ## Quick example ```php $dispatcher = new Slince\Middleware\Dispatcher([$middleware1, $middleware2]); $response = $dispatcher->process(Zend\Diactoros\ServerRequestFactory::fromGlobals()); var_dump($response instanceof Psr\Http\Message\ResponseInterface); ``` ## Usage ### Add middleware Add PSR-15 middlewares to the queue ```php use Psr\Http\Message\ServerRequestInterface; use Interop\Http\Server\MiddlewareInterface; use Interop\Http\Server\RequestHandlerInterface; use Zend\Diactoros\Response; class MyMiddleware implements MiddlewareInteface { public function process(ServerRequestInterface $request, RequestHandlerInterface $next) { $response = new Response(); $response->getBody()->write('hello world'); return $response; } } $dispatcher = new Slince\Middleware\Dispatcher([ new MyMiddleware() ]); ``` Or add a callable function directly ```php $dispatcher->push(function(ServerRequestInterface $request, RequestHandlerInterface $next){ return $delegate->process($request); }); ``` ### Dispatch ```php try { $response = $dispatcher->process(Zend\Diactoros\ServerRequestFactory::fromGlobals()); } catch (Slince\Middleware\Exception\MissingResponseException $exception) { //... } ``` A `MissingResponseException` will be thrown if the middleware did not return a invalid response or the queue was exhausted ## License The MIT license. See [MIT](https://opensource.org/licenses/MIT)