nerd-framework/nerd-container

There is no license information available for the latest version (v1.0.4) of this package.

Lightweight IoC container with dependency injection

v1.0.4 2016-11-25 14:00 UTC

This package is not auto-updated.

Last update: 2024-05-11 18:12:47 UTC


README

Build Status Coverage Status StyleCI

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"]);

Resource resolver

Not documented yet.