effectra / http-factory
Effectra HTTP Factory 包。
v1.0.1
2023-10-12 21:24 UTC
Requires
- effectra/http-message: ^1.0
- psr/http-factory: ^1.0
README
Effectra HTTP Factory 是一个 PHP 库,它提供用于创建符合 PSR-7 规范的 HTTP 消息对象的工厂类。它遵循 PSR-17 标准的 HTTP 工厂规范,确保与其他符合 PSR-7 规范的库和框架的互操作性和兼容性。
功能
- 用于创建符合 PSR-7 规范的 HTTP 消息对象的工厂类。
- 实现
psr/http-factory
接口。 - 轻松创建 HTTP 消息,如请求、响应、URI 等。
要求
- PHP 7.2 或更高版本
安装
您可以使用 Composer 安装此库。在您的项目目录中运行以下命令
composer require effectra/http-factory
使用方法
使用 StreamFactory 创建 Stream
use Effectra\Http\Factory\StreamFactory; $streamFactory = new StreamFactory(); $stream = $streamFactory->createStream('Hello, world!');
使用 RequestFactory 创建 Request
use Effectra\Http\Factory\RequestFactory; $requestFactory = new RequestFactory(); $request = $requestFactory->createRequest('GET', 'https://example.com');
使用 ServerRequestFactory 创建 ServerRequest
use Effectra\Http\Factory\ServerRequestFactory; $serverRequestFactory = new ServerRequestFactory(); $serverRequest = $serverRequestFactory->createServerRequest('POST', '/submit-form', $_SERVER);
使用 ResponseFactory 创建 Response
use Effectra\Http\Factory\ResponseFactory; $responseFactory = new ResponseFactory(); $response = $responseFactory->createResponse(200, 'OK');
使用 UriFactory 创建 Uri
use Effectra\Http\Factory\UriFactory; $uriFactory = new UriFactory(); $uri = $uriFactory->createUri('https://example.com');
有关更多示例和详细使用说明,请参阅文档。
贡献
欢迎贡献!如果您发现任何问题或对改进有建议,请在 GitHub 仓库 上提交问题或拉取请求。
许可证
Effectra HTTP Factory 是开源软件,受 MIT 许可证 的许可。
感谢您使用 Effectra HTTP Factory 库。如果您有任何问题或需要进一步的帮助,请随时联系我们。