biurad/

http-galaxy

Http Galaxy:HTTP请求、响应和CSP保护的抽象。提供对URL和cookie操作的数据清洗和实用工具。

v0.1.4 2020-06-23 04:13 UTC

README

The Poakium Http Galaxy

Latest Version Workflow Status Software License Maintenance Status

一个设计用于提供PSR-7PSR-15PSR-17无缝集成symfony/http-foundationPHP库,用于您的项目。

📦 安装

本项目需要PHP 7.4或更高版本。推荐通过Composer安装。只需运行

$ composer require biurad/http-galaxy

📍 快速开始

由于symfony/http-foundation库本身就是一个标准,依赖PHP-FIG标准的库难以与之集成。使用此库,您可以安全地使用PHP-FIG标准并获得良好的性能。通过HTTP Galaxy快速构建。

以下是如何使用此库的示例

use Biurad\Http\Factory\Psr17Factory;
use Biurad\Http\Middlewares\PrepareResponseMiddleware;
use Biurad\Http\Response;
use Laminas\Stratigility\Middleware\CallableMiddlewareDecorator;
use Laminas\Stratigility\MiddlewarePipe;
use Psr\Http\Message\{ResponseInterface, ServerRequestInterface};
use Psr\Http\Server\RequestHandlerInterface;

// Create a PSR-7 Request
$request = Psr17Factory::fromGlobalRequest();

// Create a PSR-15 Request Handler
$dispatcher = new MiddlewarePipe();
$dispatcher->pipe(new PrepareResponseMiddleware());
$dispatcher->pipe(
    new CallableMiddlewareDecorator(
        function (ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
            // Apply middleware logic here
            return $handler->handle($request);
        }
    )
);

// A request handler handling application's logic
$handler = new \App\MyRequestHandler();

// Process the request handler and middleware(s)
$response = $dispatcher->process($request, $handler);
\assert($response instanceof Response);

// Send the response to the client from symfony's response object
$response->getResponse()->send();

📓 文档

关于如何使用此库的深入文档可以在docs.biurad.com找到。还建议浏览tests目录中的单元测试。

🙌 赞助者

如果这个库被用在您的项目中,或者您有兴趣支持我们,请考虑捐赠以支持未来的开发。

👥 致谢与认可

📄 许可证

Poakium HTTP Galaxy完全免费,并按照BSD 3许可证发布。