Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ContainerFactory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| create | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of php-fast-forward/container. |
| 7 | * |
| 8 | * This source file is subject to the license bundled |
| 9 | * with this source code in the file LICENSE. |
| 10 | * |
| 11 | * @copyright Copyright (c) 2025-2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 12 | * @license https://opensource.org/licenses/MIT MIT License |
| 13 | * |
| 14 | * @see https://github.com/php-fast-forward/container |
| 15 | * @see https://github.com/php-fast-forward |
| 16 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 17 | */ |
| 18 | |
| 19 | namespace FastForward\Container; |
| 20 | |
| 21 | use FastForward\Config\ConfigInterface; |
| 22 | use FastForward\Container\Exception\InvalidArgumentException; |
| 23 | use Interop\Container\ServiceProviderInterface; |
| 24 | use Psr\Container\ContainerInterface as PsrContainerInterface; |
| 25 | |
| 26 | /** |
| 27 | * Composes a fresh container through the incremental ContainerBuilder API. |
| 28 | * |
| 29 | * This factory SHALL register the supplied initializers with a new builder and |
| 30 | * delegate assembly to it. The factory MUST NOT retain assembled container state. |
| 31 | * Source order, provider wrapper injection, and optional configuration policy |
| 32 | * SHALL remain consistent with direct builder composition. |
| 33 | */ |
| 34 | class ContainerFactory |
| 35 | { |
| 36 | /** |
| 37 | * Creates and assembles a fresh container stack. |
| 38 | * |
| 39 | * This method SHALL pass initializers to a new ContainerBuilder in supplied order. |
| 40 | * Class names MUST be instantiable without required constructor arguments. |
| 41 | * Supplied PSR-11 containers SHALL be reused without cloning their state. |
| 42 | * |
| 43 | * @param ConfigInterface|PsrContainerInterface|ServiceProviderInterface|string ...$initializers the ordered configuration objects, containers, providers, or initializer class names |
| 44 | * |
| 45 | * @return ContainerInterface the composed and autowire-enabled container |
| 46 | * |
| 47 | * @throws InvalidArgumentException if an initializer class cannot be found or adapted |
| 48 | */ |
| 49 | public static function create( |
| 50 | ConfigInterface|PsrContainerInterface|ServiceProviderInterface|string ...$initializers, |
| 51 | ): ContainerInterface { |
| 52 | return (new ContainerBuilder())->add(...$initializers)->build(); |
| 53 | } |
| 54 | } |