I am trying to create a simple MVC skeleton and I am stuck in dependencies.
This is what I have now:
$config = new Config(); $database = new Database($config); $uri = new Uri('article/5'); $request = new Request($uri); $response = new Response; $router = new Router; $dispatcher = new Dispatcher($request, $response, $router); $dispatcher->dispatch();
Question: how can any object access any dependency?
Some examples:
- To obtain output formatting options, the controller may need Config.
- Mapper queries may require a database.
- Any controller / assistant needs access to the Log.
- An assistant may require any number of dependencies (for example: Uri_Helper requires a router).
The only opportunity I can think of is to use the registry, but that violates the Demeter Law (ask what you really need).
php dependency-injection model-view-controller
Hemaulo
source share