Dependency injection containers in WordPress 01

During the holiday break I’ve looked into dependency injection containers out of a certain interest but finding one working with WordPress minimum requirements is hard.

PHP 5.2

Almost all of my work happens in WordPress and this means I have to stick to its minimum requirements almost all the time.
I use dependency injection in my code to keep it testable but that prevents almost any static based magic from happening; sure I can set some static properties of the class but that makes it stateful and defeats the purpose of a static object altogether: it’s just a typing shortcut from

$object = new Object('one', 'two');
$object->doSomething();

to

// defaults $one and $two values
Object::doSomething();

// need different $one and $two
Object::set('one', 'anotherOne');
Object::set('two', 'anotherTwo');

Object::doSomething();

which works but the extensibility of the class due to lack of late static binding is little to none and convolute.

Singleton

The anti-pattern. Fact is that for costly operations it makes sense to have one instance of a class and calls like this are convenient if the code is scattered throughout files

Singleton::instance()->getAll();

This if the instance method needs no arguments which means no dependency injection which means strong coupling, low maintainability and extensibility.

Juice

I’ve found a PHP 5.2 compatible dependency injection container and will be looking into it and how it could play along with WordPress plugins or themes. I’ve took a break from the wp-schedule project to see what I could do better in it (err… factories…) and, maybe, add another tool to the flow.

I appreciate your input