Installation
Requirements
- PHP
^8.3 - Composer
Install With Composer
composer require fast-forward/http-factory
Runtime Dependencies
The package installs the pieces it needs to work out of the box:
fast-forward/containerfor the service-provider integration helpersfast-forward/http-messagefor the specialized response and stream classes returned by the convenience methodsnyholm/psr7-serverforServerRequestCreatorpsr/http-factoryfor the PSR-17 contracts
Container Registration
When you use fast-forward/container
, register the service provider once and the package will expose both the PSR-17 services and the Fast Forward convenience factories.
use FastForward\Config\ArrayConfig;
use FastForward\Container\ContainerInterface;
use FastForward\Container\container;
use FastForward\Http\Message\Factory\ServiceProvider\HttpMessageFactoryServiceProvider;
$config = new ArrayConfig([
ContainerInterface::class => [
HttpMessageFactoryServiceProvider::class,
],
]);
$container = container($config);
Direct Instantiation
You can also use the concrete factory classes without a container. This is useful in small scripts, tests, or when you want the helper methods but not the service-provider layer.
use FastForward\Http\Message\Factory\ResponseFactory;
use FastForward\Http\Message\Factory\StreamFactory;
use Nyholm\Psr7\Factory\Psr17Factory;
$psr17Factory = new Psr17Factory();
$responseFactory = new ResponseFactory($psr17Factory);
$streamFactory = new StreamFactory($psr17Factory);
Continue to Quickstart for a minimal end-to-end example.