Fixes #4957: Adds DI container and PHPUnit tests

Formerly https://github.com/Elgg/Elgg/pull/465, this has been rebased for 1.9 with some fixes and unit tests.