|
| 1 | +# 🚀 FastForward HTTP Factory |
| 2 | + |
| 3 | +[](https://www.php.net/) |
| 4 | +[](https://opensource.org/licenses/MIT) |
| 5 | +[](https://github.com/php-fast-forward/http-factory/actions) |
| 6 | + |
| 7 | +A [PSR-11](https://www.php-fig.org/psr/psr-11/) compatible service provider that registers a fully functional set of [PSR-17](https://www.php-fig.org/psr/psr-17/) and [PSR-7](https://www.php-fig.org/psr/psr-7/) HTTP factories using [Nyholm PSR-7](https://github.com/Nyholm/psr7) and [Nyholm ServerRequestCreator](https://github.com/Nyholm/psr7-server). |
| 8 | + |
| 9 | +Designed to work out of the box with the [`php-fast-forward/container`](https://github.com/php-fast-forward/container) autowiring system. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## 📦 Installation |
| 14 | + |
| 15 | +```bash |
| 16 | +composer require fast-forward/http-factory |
| 17 | +``` |
| 18 | + |
| 19 | +## ✅ Features |
| 20 | +- Registers the Psr17Factory as the base implementation for all PSR-17 interfaces |
| 21 | +- Registers the ServerRequestCreator using InvokableFactory |
| 22 | +- Provides ServerRequestInterface::class using fromGlobals() via MethodFactory |
| 23 | +- Aliases: |
| 24 | + - RequestFactoryInterface |
| 25 | + - ResponseFactoryInterface |
| 26 | + - ServerRequestFactoryInterface |
| 27 | + - StreamFactoryInterface |
| 28 | + - UploadedFileFactoryInterface |
| 29 | + - UriFactoryInterface |
| 30 | + |
| 31 | +## 🛠️ Usage |
| 32 | + |
| 33 | +If you’re using `fast-forward/container`: |
| 34 | +```php |
| 35 | +use FastForward\Container\container; |
| 36 | +use FastForward\Config\ArrayConfig; |
| 37 | +use FastForward\Container\ContainerInterface; |
| 38 | + |
| 39 | +$config = new ArrayConfig([ |
| 40 | + ContainerInterface::class => [ |
| 41 | + // Reference the service provider by class name |
| 42 | + HttpMessageFactoryServiceProvider::class, |
| 43 | + ], |
| 44 | +]); |
| 45 | + |
| 46 | +$container = container($config); |
| 47 | + |
| 48 | +$requestFactory = $container->get(Psr\Http\Message\RequestFactoryInterface::class); |
| 49 | +$serverRequest = $container->get(Psr\Http\Message\ServerRequestInterface::class); |
| 50 | +``` |
| 51 | + |
| 52 | +## 🔧 Services Registered |
| 53 | + |
| 54 | +The following services will be automatically registered in your container when using `HttpMessageFactoryServiceProvider`: |
| 55 | + |
| 56 | +| Service Interface | Implementation Source | |
| 57 | +|------------------------------------------------------|------------------------------------------------------| |
| 58 | +| `Psr\Http\Message\RequestFactoryInterface` | `Nyholm\Psr7\Factory\Psr17Factory` (via alias) | |
| 59 | +| `Psr\Http\Message\ResponseFactoryInterface` | `Nyholm\Psr7\Factory\Psr17Factory` (via alias) | |
| 60 | +| `Psr\Http\Message\ServerRequestFactoryInterface` | `Nyholm\Psr7\Factory\Psr17Factory` (via alias) | |
| 61 | +| `Psr\Http\Message\StreamFactoryInterface` | `Nyholm\Psr7\Factory\Psr17Factory` (via alias) | |
| 62 | +| `Psr\Http\Message\UploadedFileFactoryInterface` | `Nyholm\Psr7\Factory\Psr17Factory` (via alias) | |
| 63 | +| `Psr\Http\Message\UriFactoryInterface` | `Nyholm\Psr7\Factory\Psr17Factory` (via alias) | |
| 64 | +| `Nyholm\Psr7\Factory\Psr17Factory` | Registered via `InvokableFactory` | |
| 65 | +| `Nyholm\Psr7Server\ServerRequestCreator` | Registered via `InvokableFactory`, with dependencies | |
| 66 | +| `Psr\Http\Message\ServerRequestInterface` | Created by calling `fromGlobals()` on `ServerRequestCreator` via `MethodFactory` | |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## 📂 License |
| 71 | + |
| 72 | +This package is open-source software licensed under the [MIT License](https://opensource.org/licenses/MIT). |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +## 🤝 Contributing |
| 77 | + |
| 78 | +Contributions, issues, and feature requests are welcome! |
| 79 | +Feel free to open a [GitHub Issue](https://github.com/php-fast-forward/http-factory/issues) or submit a Pull Request. |
0 commit comments