Dependency injection containers in WordPress 02

Laying out a PHP 5.2 compatible dependency injection container.

A coding direction

I’ve begun laying out the way I’d like to use the Dependency Injection Container first thing; the simplest way would be to register a class alias and get it later

$c = new tad_DI_Container();
$c->set_ctor('cache', 'MySuperCache');

...some code later...

$cache = $c->make('cache');

I’d like to be able to call static constructors too and do something like this

$c = new tad_DI_Container();
$c->set_ctor('cache', 'MySuperCache::create');

...some code later...

$cache = $c->make('cache');

to have the MySuperCache::create method called to create new instances of MySuperCache class. Empty constructors make testing code a joy and I’ve taken the habit of using static methods like create, make, one and the like.
Having the possibility to pass args to the constructor methods is a necessity and the flow might be

$c = new tad_DI_Container();
$args = array('foo', 23, 'some');
$c->set_ctor('cache', 'MySuperCache::create', $args);

...some code later...

$cache = $c->make('cache');

allowing for late arguments overriding the default ones too

$c = new tad_DI_Container();
$args = array('foo', 23, 'some');
$c->set_ctor('cache', 'MySuperCache::create', $args);

...some code later...

$late_args = array('baz', 12, 'bar');
$cache = $c->make('cache', $late_args);

While I’m not handling circular dependencies right now the possibility to quickly refer an already registered variable or instance might be implemented marking arguments with tags like @ for instances and # for variables.

$c = new tad_DI_Container();

$c->set_ctor('dep1', 'DependencyOne');
$c->set_ctor('dep2', 'DependencyTwo');
$c->set_var('hash', '2323232323232');

$args = array('@dep1', '@dep2', '#hash');
$c->set_ctor('cache', 'AnotherCache::create', $args);

...some code later...

$cache = $c->make('cache');
// same as this, except that you do not have to
// do it every time
$dep1 = new DependencyOne();
$dep2 = new DependencyTwo();
$hash = '2323232323232';
$cache = AnotherCache::create($dep1, $dep2, $hash)

Finally some singleton love

$c = new tad_DI_Container();

$c->set_singleton('cache', 'NotASingleton::create');

// $cache1 === $cache2
$cache1 = $c->make('cache');
$cache2 = $c->make('cache');

Next

I will post my progresses on the road of a PHP 5.2 compatible dependency injection container and experiment with it.

I appreciate your input