philharmony/http-factory
最新稳定版本:v1.1.0
Composer 安装命令:
composer require philharmony/http-factory
包简介
PSR-17 HTTP factory implementation for Philharmony
README 文档
README
PSR-17 HTTP factory implementation for the Philharmony framework.
Installation
composer require philharmony/http-factory
🚀 Usage
Create a Server Request
use Philharmony\Http\Factory\ServerRequestFactory; $factory = new ServerRequestFactory(); $request = $factory->createServerRequest( 'GET', 'https://example.com' );
Create a Request with Body
use Philharmony\Http\Factory\RequestFactory; use Philharmony\Http\Factory\StreamFactory; $requestFactory = new RequestFactory(); $streamFactory = new StreamFactory(); $stream = $streamFactory->createStream('Hello, Philharmony'); $request = $requestFactory->createRequest('POST', 'https://example.com') ->withBody($stream);
Create a Response
use Philharmony\Http\Factory\ResponseFactory; $response = (new ResponseFactory())->createResponse(200);
Create a Stream
use Philharmony\Http\Factory\StreamFactory; $streamFactory = new StreamFactory(); // From string $stream = $streamFactory->createStream('Hello'); // From file $stream = $streamFactory->createStreamFromFile('/path/to/file.txt'); // From resource $stream = $streamFactory->createStreamFromResource(fopen('php://temp', 'r+'))
Create an Uploaded File
use Philharmony\Http\Factory\UploadedFileFactory; use Philharmony\Http\Factory\StreamFactory; $stream = (new StreamFactory())->createStream('file content'); // From stream $uploadedFile = (new UploadedFileFactory())->createUploadedFile( $stream, $stream->getSize(), UPLOAD_ERR_OK, 'file.txt', 'text/plain' ); // From file $uploadedFileFromFile = (new UploadedFileFactory())->createUploadedFileFromFile( fileOrStream: '/path/to/file.txt', size: null, // used filesize errorStatus: UPLOAD_ERR_OK, clientFilename: 'file.txt', clientMediaType: 'text/plain', fullPath: '/path/to/file.txt' // PHP 8.1+ support );
Create a URI
use Philharmony\Http\Factory\UriFactory; $uri = (new UriFactory())->createUri('https://example.com/path');
🧪 Testing
The package is strictly tested with PHPUnit 10 to ensure full compliance with HTTP standards and RFCs.
Run Tests
composer test
Code Coverage
composer test:coverage
🏗️ Static Analysis & Code Style
Verified with PHPStan Level 9 to ensure total type safety and prevent runtime errors.
composer phpstan
Check and fix code style (PSR-12):
composer cs-check composer cs-fix
📄 License
This package is open-source and licensed under the MIT License. See the LICENSE file for details.
🤝 Contributing
Contributions, issues, and feature requests are welcome.
If you find a bug or have an idea for improvement, please open an issue or submit a pull request.
⭐ Support
If you find this package useful, please consider giving it a star on GitHub. It helps the project grow and reach more developers.
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-26