trq Posted July 19, 2011 Share Posted July 19, 2011 Hi guys, it's been a long while since I've actually asked a question on these forums but I'm in a bit of a predicament at the moment trying to resolve an issue of what is responsible for what (between my Router & Dispatcher). I have a working Router implemented which takes a series of Route patterns and matches them against a given URL. The first to match successfully will have my Router return a Command object full of all the goodies my Dispatcher needs (name of controller, action and any other parameters). At the moment this Command object would be passed to the Dispatcher to initiate the controller and dispatch the action. It is however right at this same point that I am a little stuck with how to handle things. I would very much like to have the ability (as most frameworks do) to default back to a default Module, Controller & Action if the Route returned by my Router is not dispatchable as is. Here is where the problem lies. What (between the Router & the Dispatcher) do you guys think should be responsible for injecting these defaults? On one had I have a Router which in my eyes should simply match patterns to urls and hand control to something else when it's done. On the other hand, I don't want the Dispatcher to be playing around with what is (at this stage) considered a valid Route. A big part of me want's this to be handled at the Router. I already have plans for another step in the bootstrap process to sit between the Router and Dispatcher but it (this other step) will definitely require knowledge of what is about to be dispatched. However allot of code that I have seen seems to have the Dispatcher attempt to load what the Router has given it, and if it can't the dispatcher itself starts injecting defaults until it can. Any thoughts on the subject would be much appreciated. Thanks. (There is a link to the project in my signature if looking at the code helps) Quote Link to comment https://forums.phpfreaks.com/topic/242293-router-dispatch-design-issue/ Share on other sites More sharing options...
requinix Posted July 19, 2011 Share Posted July 19, 2011 I would stick it in the Router. The Dispatcher shouldn't have to care about what Route it got so long as the Command information is correct (and even then it might not have to care about that). The Router is the one responsible for deciding which Route should be served, and if it has to use defaults to do so then so be it. Keep the clear separation of route matching and route execution. Buzzword bingo includes "encapsulation" (using it) and "coupling" (decreasing it). After all, the defaults should be part of the route data, and if you've having the Dispatcher look at that stuff anyways then why use a Router? Go with your gut on this. Quote Link to comment https://forums.phpfreaks.com/topic/242293-router-dispatch-design-issue/#findComment-1244367 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.