Dependency injection containers in WordPress 05

Another bit of smartness for a PHP 5.2 compatible dependency injection container.

Simpler syntax for simpler object

If an object requires no further method call to be ready to be used after its __construct method has been called, either because its __construct method does it all or the object is one not requiring any initialization, then the syntax can be shortened using the ~ charachter.
Given a dependency injectable class like this

class My_App_Status_Checker {
    public function __construct(App_Status_I $status, Logger_I $logger){

This is a perfectly legit approach and code

$c = new tad_DI52_Container();

$c->set_ctor('status', 'My_App_Status');
$c->set_ctor('logger', 'My_Logger');

$args = array('@status', '@logger');
$c->set_ctor('status_checker', 'My_App_Status_Checker', $args);

that can be shortened to this

$c = new tad_DI52_Container();

$args = array('~My_App_Status', '~My_Logger');
$c->set_ctor('status_checker', 'My_App_Status_Checker', $args);

and have the same effect. The version of the repository implementing it is on GitHub.


Some reflection to make the dependency injection container a better player of the guessing game.