Dependency Injection with PHP

I used to develop using Singletons, registries or even static classes. Those days are gone.

I decided to use Dependency Injection so that:

I gave a try to Symfony and ZF2 DI systems, but they both seem way too complicated for just a simple need (that anyone who has worked with Spring would understand):

class MyClass {
    /**
     * @Inject
     * @var MyService
     */
    private $service;
}

This short code means: Inject, using a simple annotation, an instance of another class into a property.

I started working on a framework enabling such functionality few months ago. It is now in a mature state. It is based on the Annotations library of Doctrine 2, and takes most of its ideas of Spring 3.

You can check out this framework on its official website: PHP-DI, and you are welcome to use it or contribute.

Comments