biurad / biurad-http

该软件包已被废弃,不再维护。作者建议使用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

一个设计用于提供与symfony/http-foundation无缝集成的PHP库,以实现PSR-7PSR-15PSR-17标准,以供您的项目使用。

📦 安装

该项目需要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许可证发布。