vaibhavpandeyvpz / vidyut
No frills PSR-7 request handler based on PSR-15 specification.
2.0
2020-04-23 06:54 UTC
Requires
- php: ^7.0
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- phpunit/phpunit: ^4.0 || ^5.0
- vaibhavpandeyvpz/sandesh: ^2.0
Provides
This package is auto-updated.
Last update: 2024-12-23 16:56:55 UTC
README
No frills PSR-7 request handler based on PSR-15 specification.
Vidyut:
विद्युत्
(Electricity)
Install
composer require vaibhavpandeyvpz/vidyut
# You will also need a PSR-7 implementation
composer require vaibhavpandeyvpz/sandesh
Usage
<?php /** * @desc Middleware can be an instance of Psr\Http\Server\MiddlewareInterface or a callable with similar signature. */ $pipeline = new Vidyut\Pipeline(); $pipeline->pipe(function ($request, $delegate) { if ($request->getUri()->getPath() === '/login') { $response = (new Sandesh\ResponseFactory())->createResponse(); $response->getBody()->write('Login'); return $response; } return $delegate->process($request); }); $pipeline->pipe(function ($request, $delegate) { if ($request->getUri()->getPath() === '/logout') { $response = (new Sandesh\ResponseFactory())->createResponse(); $response->getBody()->write('Logout'); return $response; } return $delegate->process($request); }); $pipeline->pipe(function () { $response = (new Sandesh\ResponseFactory())->createResponse(); $response->getBody()->write('Page could not be found.'); return $response->withStatus(404); }); $request = (new Sandesh\ServerRequestFactory()) ->createServerRequest($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $_SERVER); $response = $pipeline->handle($request);
License
See LICENSE.md file.