Container with Dependency Injection for Nerd Framework.
Get the container:
$container = new \Nerd\Framework\Container\Container();
Bind class constructor:
$container->bind('foo', Foo::class);
Bind callable factory:
$container->bind('factory', function () {
return new Factory();
});
Bind singleton:
$container->singleton('single', SingletonService::class);
Retrieve resources from container:
$foo = $container->get('foo');
Invoke function, class method or class constructor with dependency injection:
$result = $container->invoke(function (FooFactoryInterface $factory) {
// $foo will be injected using parameter name
// $other will be injected using Bar type hint
return $factory->makeFoo();
});
Pass additional resources into invoke() method:
$result = $container->invoke(function ($foo, $a, $b) {
//
}, ["a" => "Hello", "b" => "World"]);
Not documented yet.