Where to issue final common logic

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Where to issue final common logic

jsuggs
I'm wanting to do some cleanup commands (ex. issue Doctrine "flush") after all activity has completed (ie. no more [state] changes).

Where is the most logical place to issue that command?

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Where to issue final common logic

David Mintz


On Thu, Apr 8, 2010 at 6:26 PM, jsuggs <[hidden email]> wrote:

I'm wanting to do some cleanup commands (ex. issue Doctrine "flush") after
all activity has completed (ie. no more [state] changes).

Where is the most logical place to issue that command?


Maybe a controller plugin's dispatchLoopShutdown() hook?

--
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Reply | Threaded
Open this post in threaded view
|

Re: Where to issue final common logic

Hector Virgen
Are you concerned with the result of Doctrine's flush? If so, I'd suggest flushing before rendering the layout by using the postDispatch hook in a controller plugin. If you use dispatchLoopShutdown hook, the layout will already have been rendered.

You'll need to test if the request has finished dispatching first:

class MyPlugin extends Zend_Controller_Plugin_Abstract
{
    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {
        // Return early if forward is detected
        if (!$request->isDispatched()) return;

        // Flush Doctrine here and update layout placeholders if necessary
    }
}

--
Hector


On Fri, Apr 9, 2010 at 1:30 PM, David Mintz <[hidden email]> wrote:


On Thu, Apr 8, 2010 at 6:26 PM, jsuggs <[hidden email]> wrote:

I'm wanting to do some cleanup commands (ex. issue Doctrine "flush") after
all activity has completed (ie. no more [state] changes).

Where is the most logical place to issue that command?


Maybe a controller plugin's dispatchLoopShutdown() hook?

--
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/



--
Hector Virgen
Reply | Threaded
Open this post in threaded view
|

Re: Where to issue final common logic

jsuggs
Hector Virgen wrote
Are you concerned with the result of Doctrine's flush?
Yes and no.  The only reason I was looking to have it in a single place was so that the flush could cover the entire Unit Of Work (and it also makes it somewhat "set it and forget it").  However, since there were places where I was going to need to ensure that the flush occurred correctly and be able to trap (and respond to) any errors, I ended up explicitly calling flush in my service layer after persisting the objects.  I'm still not sure if this is the best design approach but it doesn't seem too bad now that I've got it working.

Side note, I did test using a postDispatch hook.  I'm relatively new to ZF, even though I've been following/reading/learning for a while I'm just starting to actually use it for a project and once you've got your head wrapped around the concepts of using the various pieces (like the postDispatch plugin) they not only start to make sense (and you realize and appreciate their design), but you are able to develop much more quickly than "rolling your own".  So my point to that rambling is that I've been surprised at my development efficiency using ZF and I'd highly recommend to anyone to take the time to learn the framework (ie. read the manual cover to cover) and follow/read other (ZF) developer's blogs (so you can learn from their experience/mistakes).

Also, a very big kudos to the communities surrounding both ZF and Doctrine as they have both been very helpful in helping me get over those first few "newbie" questions.  I hope that I'll soon be able to contribute back both in development as well as just general help.