Breaking changes - this package has been rewritten from scratch to be more strict and simple to use.
- Container is immutable.
- Support for PSR-11 Container Interface.
- Support for setting default parameters on definitions.
$myClass = (new Container())->make(MyClass::class);
Type-hints will be resolved if they are bound in advance.
$containerBuilder = new ContainerBuilder();
$containerBuilder->bind('myClass', MyClass::class)
->setArgument('firstname', 'Roger');
$container = new Container($containerBuilder);
$myClass = $container->make('myClass', [
'lastname' => 'Moore'
]);
$containerBuilder = new ContainerBuilder();
$containerBuilder->bindClass(MyClass::class);
$container = new Container($containerBuilder);
$myClass = $container->get(MyClass::class);
interface MyClassInterface
{
}
class MyClass implements MyClassInterface
{
}
$containerBuilder = new ContainerBuilder();
$containerBuilder->bindClassOnInterface(MyClass::class);
$container = new Container($containerBuilder);
$myClass = $container->get(MyClassInterface::class);
Parameters will be resolved in following order:
- Type-hint ContainerInterface will be resolved to instance of container.
- Default parameters specified on definition.
- Default parameters in constructor/method.
- Specified parameters when calling make() and not already resolved.