I am creating a MVC-ish framework in PHP. I am trying to implement a DI Container to allow the creation of controller objects (among others).
My MVC framework is pretty typical. Each module (or component if you wish) has a controller responsible for executing requests. These module controllers typically extend a base Controller
class. All controllers will accept Request
and Response
objects as arguments.
The confusion occurs because some controllers may need different arguments in order to function. For example: Many controllers will need a Database
object; Controllers which send mail may need a Mailer
object; while a controller which logs data may need a Log
object. The DI Container will contain the recipes for creating all these controllers.
My front controller needs to be able create any of these controller objects, as specified by a request. Furthermore, each controller needs to be able to create any other controller.
How do I get my front controller and module controllers to access the DI Container in a way that doesn't result in a dependency on the DI Container by each controller?
I actually don't mind if the front controller is dependent on the container, I am more concerned about the module controllers.
Thanks,