Re: [fw-general] Re[fw-general] agrding the current Dispatch process...

2008-07-25 Thread Matthew Weier O'Phinney
-- David Rogers <[EMAIL PROTECTED]> wrote
(on Thursday, 24 July 2008, 09:42 AM -0700):
> Hey, all. I feel like I must have missed something at some point, but has the
> Dispatch process changed at some point? Here's what I remember:
> 
> 1. Front Controller instantiates the Request, Response, Router, and
> Dispatcher objects;
> 2. Dispatcher gets information about initial dispatch from Request and
> Router;
> 3. Dispatcher instantiates the appropriate Controller object, which also
> runs Controller->init();
> 3a. Dispatcher calls Controller->preDispatch();
> 3b. Dispatcher calls Controller->{$Request->getActionName()}Action();
> 3c. Dispatcher fields additional dispatch requests (a la
> Controller->_forward()), repeat 3...
> 3d. Dispatcher calls Controller->postDispatch();
> 4. Dispatcher returns to Front Controller;
> 5. Front Controller outputs the Response.

Nope, you've got this flow wrong. Should be:

1.  Request/Response/Router/Dispatcher initialization
2.  routeStartup()
* call plugins registered with this hook
3.  Routing
* Updates Request object based on matched information from
  routing
4.  routeShutdown()
* call plugins registered with this hook
5.  dispatchLoopStartup()
* call plugins registered with this hook
6.  preDispatch()
* call plugins registered with this hook
7.  Dispatch action
8.  action helper preDispatch()
9.  action controller preDispatch()
10. action method
* UNLESS a _forward() or redirect has occurred
11. action controller postDispatch()
12. action helper postDispatch()
13. postDispatch()
* call plugins registered with this hook
/* repeat 6 - 13 as necessary */
14. dispatchLoopShutdown()
* call plugins registered with this hook
15. send response

This has been the flow since before 0.9.0 (and that version simply added
the action helpers; all else has been the case since 0.6.0).

> This structure precedes the ActionStack, of course, but the important thing
> to note is that the postDispatch (hook) method was not called until the
> whole loop completed.

First, ActionStack is a combination Plugin/action helper. It does
not precede any of this; it was built to take advantage of it.

Second, as you can see, postDispatch() has always been _within_ the
loop. dispatchLoopShutdown() has been outside of it.

> From experience, it appears that postDispatch() is now executed after the
> action resolves, prior to initiating the next loop (3c and 3d are switched).
> The manual and the API docs don't clearly represent this, if this is the
> case, although the routing diagram in the manual kinda does. The docs for
> Controller::_forward() don't clearly indicate where the re-dispatching
> occurs, either. :/

_forward() does two things. If called in preDispatch() (any of them), it
will halt execution of the current action, and cause a new iteration of
the loop. When called during an action or during postDispatch() (any of
them), it will trigger an additional iteration of the dispatch loop. If
you feel this could be made clearer in the manual, please open an issue;
ideally, please submit a patch to the manual docbook.

> Somebody else please confirm this process! It's important to note the
> difference... Personally, I'd much rather see Controller::_forward()
> interrupt the dispatch loop (as it used to) 

As noted, it does.

> and ActionStack preserve it,

And, as noted, this simply works within the dispatch loop. It triggers
at postDispatch(), and if no _forward() calls are detected, and actions
exist in its stack, it triggers.

> even if that means I write Zend_Controller_Action_Helper_Forwarder (a la
> Redirector) to do so. I'm not certain there's a method to do so, however, as
> the docs on plugins and helpers are a little vague on the subject as well.
> 
> Is there an authoritative resource somewhere on how the dispatch loop
> actually operates? I've done a little snooping about on the Wiki, and there
> are pieces from the 1.1 revision that reference the new Router scheme and
> possible changes to the looping process, but I haven't found that one page
> that says "this is how we do it" yet... Thanks...!

It's in the Zend_Controller docs. As mentioned, if you feel it could be
more clear, please post an issue.

-- 
Matthew Weier O'Phinney
Software Architect   | [EMAIL PROTECTED]
Zend Framework   | http://framework.zend.com/


[fw-general] Re[fw-general] agrding the current Dispatch process...

2008-07-24 Thread David Rogers

Hey, all. I feel like I must have missed something at some point, but has the
Dispatch process changed at some point? Here's what I remember:

1. Front Controller instantiates the Request, Response, Router, and
Dispatcher objects;
2. Dispatcher gets information about initial dispatch from Request and
Router;
3. Dispatcher instantiates the appropriate Controller object, which also
runs Controller->init();
3a. Dispatcher calls Controller->preDispatch();
3b. Dispatcher calls Controller->{$Request->getActionName()}Action();
3c. Dispatcher fields additional dispatch requests (a la
Controller->_forward()), repeat 3...
3d. Dispatcher calls Controller->postDispatch();
4. Dispatcher returns to Front Controller;
5. Front Controller outputs the Response.

This structure precedes the ActionStack, of course, but the important thing
to note is that the postDispatch (hook) method was not called until the
whole loop completed.

>From experience, it appears that postDispatch() is now executed after the
action resolves, prior to initiating the next loop (3c and 3d are switched).
The manual and the API docs don't clearly represent this, if this is the
case, although the routing diagram in the manual kinda does. The docs for
Controller::_forward() don't clearly indicate where the re-dispatching
occurs, either. :/

Somebody else please confirm this process! It's important to note the
difference... Personally, I'd much rather see Controller::_forward()
interrupt the dispatch loop (as it used to) and ActionStack preserve it,
even if that means I write Zend_Controller_Action_Helper_Forwarder (a la
Redirector) to do so. I'm not certain there's a method to do so, however, as
the docs on plugins and helpers are a little vague on the subject as well.

Is there an authoritative resource somewhere on how the dispatch loop
actually operates? I've done a little snooping about on the Wiki, and there
are pieces from the 1.1 revision that reference the new Router scheme and
possible changes to the looping process, but I haven't found that one page
that says "this is how we do it" yet... Thanks...!

David @ OrlandoPHP.org
-- 
View this message in context: 
http://www.nabble.com/Reagrding-the-current-Dispatch-process...-tp18635886p18635886.html
Sent from the Zend Framework mailing list archive at Nabble.com.