vaibhavpandeyvpz / vidyut
基于 PSR-15 规范的无花哨 PSR-7 请求处理器。
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-08-23 16:12:07 UTC
README
基于 PSR-7 的无花哨请求处理器,遵循 PSR-15 规范。
Vidyut:
विद्युत्
(电力)
安装
composer require vaibhavpandeyvpz/vidyut
# You will also need a PSR-7 implementation
composer require vaibhavpandeyvpz/sandesh
使用方法
<?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.md 文件。