Files
itflow/libs/vendor/guzzlehttp/psr7/docs/psr-17-factories.md
2026-08-02 01:26:40 -04:00

1.4 KiB

PSR-17 Factories

This page explains GuzzleHttp\Psr7\HttpFactory, the PSR-17 factory implementation provided by this package. Use it when code expects PSR-17 factory interfaces and you want factories that create Guzzle PSR-7 messages, streams, uploaded files, and URIs.

GuzzleHttp\Psr7\HttpFactory

GuzzleHttp\Psr7\HttpFactory implements all PSR-17 factory interfaces: RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, and UriFactoryInterface.

use GuzzleHttp\Psr7\HttpFactory;

$factory = new HttpFactory();

$request = $factory->createRequest('GET', 'https://example.com');
$response = $factory->createResponse(200);
$serverRequest = $factory->createServerRequest('POST', '/submit', ['REMOTE_ADDR' => '192.0.2.1']);
$stream = $factory->createStream('body');
$uri = $factory->createUri('https://example.com/path');

It also creates streams from files and resources, and uploaded files from streams.

$stream = $factory->createStreamFromFile('/path/to/file.txt', 'r');
$upload = $factory->createUploadedFile($stream, $stream->getSize(), UPLOAD_ERR_OK, 'file.txt', 'text/plain');