Skip to main content
Version: v2.0 (upcoming)

HTTP Factories

config/packages/http.php binds the PSR-17 HTTP factory interfaces to their Guzzle-based implementations.

What it does

Maps the three PSR-17 factory interfaces to concrete classes from php-http/guzzle7-factory:

InterfaceImplementation
ResponseFactoryInterfaceHttp\Factory\Guzzle\ResponseFactory
StreamFactoryInterfaceHttp\Factory\Guzzle\StreamFactory
UriFactoryInterfaceHttp\Factory\Guzzle\UriFactory

These bindings allow any service that type-hints a PSR-17 interface to receive the correct factory via autowiring.

Dependencies

PackageDescription
php-http/guzzle7-factoryPSR-17 factory implementations backed by Guzzle 7.

Swapping the HTTP factory

To use a different PSR-17 implementation (e.g. nyholm/psr7), replace the bindings in services.php:

// services.php
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;
use function DI\autowire;

ResponseFactoryInterface::class => autowire(Psr17Factory::class),
StreamFactoryInterface::class => autowire(Psr17Factory::class),
UriFactoryInterface::class => autowire(Psr17Factory::class),