How PHP-DI works

Do you want to help out improving PHP-DI? Or are you simply curious? Here is a short presentation of how PHP-DI works.

Global architecture

The main component is the Container class. It is created by a ContainerBuilder, which is just a helper class.

It is the entry point from the user's point of view, it is also the component that coordinates all other sub-components.

Its main role is to return entries by their entry name:

$entry = $container->get('entryName');

A container instance has the following sub-components:


A definition defines what an entry is:

The class definition describes how the container should create a class instance (what parameters the constructor takes, …).