|
1 | 1 | Integration |
2 | 2 | =========== |
3 | 3 |
|
4 | | -The Fast Forward Framework is designed to integrate seamlessly with other PSR-compliant packages and libraries. You can add or override service providers as needed to customize your application's infrastructure. |
| 4 | +Fast Forward Framework is intentionally small and integrates best when you treat it as a bootstrap |
| 5 | +layer for the rest of your application. |
| 6 | + |
| 7 | +Integrate with the Fast Forward container |
| 8 | +---------------------------------------- |
| 9 | + |
| 10 | +The recommended integration path is the ``container()`` helper from ``fast-forward/container``. |
| 11 | + |
| 12 | +.. code-block:: php |
| 13 | +
|
| 14 | + use FastForward\Framework\ServiceProvider\FrameworkServiceProvider; |
| 15 | + use function FastForward\Container\container; |
| 16 | +
|
| 17 | + $container = container(new FrameworkServiceProvider()); |
| 18 | +
|
| 19 | +Integrate through configuration |
| 20 | +------------------------------- |
| 21 | + |
| 22 | +When you want your provider list to live in configuration, you can pass a config object into the |
| 23 | +container helper: |
| 24 | + |
| 25 | +.. code-block:: php |
| 26 | +
|
| 27 | + use App\ServiceProvider\AppServiceProvider; |
| 28 | + use FastForward\Config\ArrayConfig; |
| 29 | + use FastForward\Container\ContainerInterface; |
| 30 | + use FastForward\Framework\ServiceProvider\FrameworkServiceProvider; |
| 31 | + use function FastForward\Container\container; |
| 32 | +
|
| 33 | + $config = new ArrayConfig([ |
| 34 | + ContainerInterface::class => [ |
| 35 | + FrameworkServiceProvider::class, |
| 36 | + AppServiceProvider::class, |
| 37 | + ], |
| 38 | + ]); |
| 39 | +
|
| 40 | + $container = container($config); |
| 41 | +
|
| 42 | +This keeps environment-specific providers in one place and works well with the rest of the |
| 43 | +configuration package. |
| 44 | + |
| 45 | +HTTP runtime versus CLI runtime |
| 46 | +------------------------------- |
| 47 | + |
| 48 | +The framework provider registers ``Psr\Http\Message\ServerRequestInterface`` by calling |
| 49 | +``fromGlobals()`` through the downstream HTTP factory provider. That is convenient in web |
| 50 | +contexts, but it also means you should be deliberate in CLI commands and automated tests. |
| 51 | + |
| 52 | +For CLI or tests, prefer explicit request creation: |
| 53 | + |
| 54 | +.. code-block:: php |
| 55 | +
|
| 56 | + use Psr\Http\Message\RequestFactoryInterface; |
| 57 | +
|
| 58 | + $requestFactory = $container->get(RequestFactoryInterface::class); |
| 59 | + $request = $requestFactory->createRequest('GET', 'https://example.test/health'); |
| 60 | +
|
| 61 | +PSR-oriented application services |
| 62 | +--------------------------------- |
| 63 | + |
| 64 | +Because the container exposes PSR interfaces, your application code can type-hint the standard |
| 65 | +contracts instead of framework-specific implementations: |
| 66 | + |
| 67 | +.. code-block:: php |
| 68 | +
|
| 69 | + use Psr\Http\Client\ClientInterface; |
| 70 | + use Psr\Http\Message\ResponseFactoryInterface; |
| 71 | +
|
| 72 | + final readonly class StatusPageAction |
| 73 | + { |
| 74 | + public function __construct( |
| 75 | + private ClientInterface $client, |
| 76 | + private ResponseFactoryInterface $responseFactory, |
| 77 | + ) {} |
| 78 | + } |
| 79 | +
|
| 80 | +This keeps your domain services portable even when you rely on the Fast Forward ecosystem for |
| 81 | +bootstrap and defaults. |
0 commit comments