philharmony / http-factory
PSR-17 HTTP factory implementation for Philharmony
v1.1.0
2026-03-29 16:08 UTC
Requires
- php: ^8.1
- philharmony/http-enum: ^1.3
- philharmony/http-message: ^1.4
- philharmony/http-psr-extension: ^1.0
- psr/http-factory: ^1.1
- psr/http-message: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^10.0
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.