Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | n/a |
0 / 0 |
|
| FastForward\Container\container | |
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 | * Creates and assembles a fully composed container instance. |
| 28 | * |
| 29 | * This convenience function delegates composition to ContainerFactory::create(). |
| 30 | * Accepted initializers include: |
| 31 | * - PSR-11 container instances |
| 32 | * - Service providers implementing ServiceProviderInterface |
| 33 | * - Configuration instances implementing ConfigInterface |
| 34 | * - Class names as strings (which MUST be instantiable) |
| 35 | * |
| 36 | * If a ConfigContainer is included, it SHALL attempt to resolve additional nested container |
| 37 | * definitions from its configuration using the key `${alias}.${ContainerInterface::class}`. |
| 38 | * Unknown initializer classes and unsupported constructed objects MUST result in |
| 39 | * an InvalidArgumentException being thrown. |
| 40 | * |
| 41 | * The final container returned is an AutowireContainer that wraps an |
| 42 | * AggregateContainer composed of all resolved sources. |
| 43 | * |
| 44 | * @param ConfigInterface|PsrContainerInterface|ServiceProviderInterface|string ...$initializers |
| 45 | * A variadic list of container initializers, optionally including config or provider classes. |
| 46 | * |
| 47 | * @return ContainerInterface the composed and autowire-enabled container |
| 48 | * |
| 49 | * @throws InvalidArgumentException if an initializer class cannot be found or adapted |
| 50 | */ |
| 51 | function container( |
| 52 | ConfigInterface|PsrContainerInterface|ServiceProviderInterface|string ...$initializers, |
| 53 | ): ContainerInterface { |
| 54 | return ContainerFactory::create(...$initializers); |
| 55 | } |