Chapter 9: Dependency Injection Example
In this chapter, we are going to look at a very popular pattern in modern PHP – the dependency injection (DI) container. This is a system that acts as a global application-level factory and combines configuration and instance management.
You could have a read through Fabien Potencier's article from way back in 2009, which tried to educate the PHP masses about what a DI container is and why we should be using one:
http://fabien.potencier.org/do-you-need-a-dependency-injection-container.html.
Bear in mind that this is a vintage article, but the basic points are all there, and it is worth a read through. It's also an interesting bit of PHP history.
We're going to learn all about what a DI container does by building our own toy DI container. Hopefully, this will help clarify how simple the concept is, something that is not always easy when you try to delve into the code of real DI containers.
This chapter will...