philharmony/http-factory

PSR-17 HTTP factory implementation for Philharmony

Maintainers

Package info

github.com/philharmonytech/http-factory

pkg:composer/philharmony/http-factory

Statistics

Installs: 24

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1.0 2026-03-29 16:08 UTC

This package is auto-updated.

Last update: 2026-04-29 16:21:42 UTC


README

Validate Analysis Test codecov PHP Version Latest Stable Version Total Downloads License

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.