The League\Di library provides a fast and powerful Dependency Injection Container for your application.
Via Composer
{
"require": {
"league/di": "1.*"
}
}
include 'vendor/autoload.php';
$container = new League\Di\Container;
$container->bind('\Foo\Bar\BazInterface', '\Foo\Bar\Baz');
The Di Container is able to recursively resolve objects and their dependencies by inspecting the type hints on an object's constructor.
namespace Foo\Bar;
class Baz
{
public function __construct(Qux $qux, Corge $corge)
{
$this->qux = $qux;
$this->corge = $corge;
}
public function setQuux(Quux $quux)
{
$this->quux = $quux;
}
}
$container->resolve('\Foo\Bar\Baz');
Alternatively, you can specify what to inject into the class upon instantiation.
$container->bind('\Foo\Bar\Baz')->addArgs(array('\Foo\Bar\Quux', '\Foo\Bar\Corge'));
$container->resolve('\Foo\Bar\Baz');
$container->bind('\Foo\Bar\Baz')->withMethod('setQuux', array('\Foo\Bar\Quux'));
$container->resolve('\Foo\Bar\Baz');
- Extensive Documentation
- More Framework Integration
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.


