I'm trying to create simple MVC skeleton and I'm stuck with 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(); // Routing, instantiate controller, execute action, send response The question is: how can any object get access to any dependency?
Some examples:
- Controller may need Config to get output formatting options.
- Mapper may need Database to perform queries.
- Any Controller / Helper needs access to Log.
- Helper may need any number of dependencies (ex.:Uri_Helper needs Router).
The only possibility I can think of is to use Registry, but this violates Law of Demeter (ask what you really need).