Re: Event Dispatcher and Failed Posted Notifications
| From: | Bertrand Mansion | Date: | Wed, 26 Jan 2005 16:22:38 +0000 |
| Subject: | Re: Event Dispatcher and Failed Posted Notifications | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-17174@lists.php.net to get a copy of this message | ||
Michael Caplan wrote:
>Bertrand et al,
>
>
>
>I have been paying close attention to the proposed / approved Event
>Dispatcher, as it seems to provide a very elegant solution to the problem of
>inter-module coupling. I have spent some time in the code and working
>through the unit tests to figure out how Event Dispatcher works. I think I
>have my head around most of it, but there is one issue I can't seem to
>figure out and I am hoping you or anyone else can help me solve it.
>
>
>
>The scenario is this: I am coding in an environment which has several
>defined modules. Each module provides unique functionality (eg: article
>module, calendar module, tracker module, etc....). Under certain scenarios,
>these modules will need to interface with each other (eg: an article is
>posted into the article module which requires the tracker module to be
>updated so that it can track access to the article - or something like
>that). So, module A posts an event (which is to be handled immediately)
>which the dispatcher then forwards to an observer in module B. All good.
>But let's say the event posted to module B fails. For whatever reason,
>module A has a strong dependency on module B doing it's work, and upon
>failure of module B's handled event it would be most desirable that module A
>rolls back. Is there a way that the event poster can become aware of an
>event failure (presuming it is an immediately posted event)?
I think this might be better handled by exceptions if PHP5 is an option for you.
You can also have object A (the poster) be the contained notification object
(this is the usual way to go anyway) and have B (the receiver) use the contained
object like suck:
// In B, this is your callback
function receiverMethod(&$notification)
{
// Do some work...
if ($failed) {
$A =& $notification->getNotificationObject();
$A->rollback();
$notification->cancelNotification();
}
}
Good luck,
Bertrand Mansion
Mamasam