A PSR-11 compliant aggregate container for PHP, designed to unify and resolve services across multiple container implementations. Built to work seamlessly with php-di, configuration objects, and custom container stacks.
- Aggregates multiple containers
- Caches resolved entries
- Integrates with
php-di - First-class support for configuration containers
- Incremental composition with
ContainerBuilder - PSR-11 compliant
composer require fast-forward/containeruse FastForward\Container\ContainerInterface;
use function FastForward\Container\container;
use FastForward\Config\ArrayConfig;
$config = new ArrayConfig([
ContainerInterface::class => [
SomeServiceProvider::class, // strings will be initialized with a new call
SomePsr11Container::class, // strings should be initializable with a simple new call
new OtherServiceProvider('withArgument'), // objects that implement Interop\Container\ServiceProviderInterface
new ServiceManager($dependencies), // objects that implement Psr\Container\ContainerInterface
],
]);
$container = container($config);
// or using the container function directly with a configuration variadic
// $container = container(
// SomeServiceProvider::class,
// SomePsr11Container::class,
// new ApplicationConfig(), // that implements ConfigInterface with the ContainerInterface key
// new OtherServiceProvider('withArgument'),
// new ServiceManager($dependencies),
// );
// Retrieve service
$service = $container->get(SomeService::class);The same composition is available through a static method:
use FastForward\Container\ContainerFactory;
$container = ContainerFactory::create($config);Both forms accept the same variadic initializers. Each call creates a fresh
aggregate, provider adapters, and autowiring container; supplied PSR-11 container
objects are reused. Unsupported initializer classes raise InvalidArgumentException.
For conditional registration or setup across several stages, use the incremental builder:
use FastForward\Container\ContainerBuilder;
$builder = (new ContainerBuilder())->add($config);
if ($featureEnabled) {
$builder->add($featureProvider);
}
$container = $builder->build();add() accepts the same initializers and preserves registration order. Each
build() creates a fresh composition; adding sources later affects subsequent
builds only. Supplied source objects are reused, so independent composition
caches do not imply cloning external containers or their services.
ContainerFactory::create() delegates to this same builder implementation.
This package is licensed under the MIT License. See the LICENSE file for more details.
