Re: Use of Event_Dispatcher package

From: Date: Wed, 02 Mar 2005 14:28:33 +0000
Subject: Re: Use of Event_Dispatcher package
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-36453@lists.php.net to get a copy of this message
Philippe Jausions wrote:
Stephan Schmidt wrote:
Philippe Jausions schrieb:
1. Event_Dispatcher doesn't seem to have a built-in notification for addObserver and so on...
What keeps you from doing something like: File_Monitor_Event_Dispatcher extends Event_Dispatcher { function addObserver(...) {
    $this->post($this, 'ObserverAdded');
    parent::addObserver(...);
} } Triggering notifications for every observer added certainly is not a feature I'd like to include in Event_Observer directly, as it can be easily wrapped in a new class...
Yes, I thought about something like that too. However, I had some mixed feelings about it, due to the convenience of Event_Dispatcher::getInstance(). I wanted to avoid having multiple instances of Event_Dispatcher going around as it makes more sense to have only one, or at least to have only one way to get it.
Do you think a Event_Dispatcher_Observable separate class could be distributed along the Event_Dispatcher package...? If I can see the use of observing observers being added to the dispatcher, maybe some others will... Just trying to prevent the next guy to reinvent the wheel. No big deal, and doesn't make much difference to me, but it would be nice to have that standard (in a separate file), so this way I could use type hinting in my PHP 5 package... /** * Wrapper class to Event_Dispatcher to be able to observe objects being added/removed */ class Event_Dispatcher_Observable extends Event_Dispatcher { /**
    * Fires a "ObserverAdded" event
    *
    * @see Event_Dispatcher::addObserver()
    */
   function addObserver($callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null)
{
       $this->post($this, 'ObserverAdded');
       parent::addObserver($callback, $nName, $class);
} /**
    * Fires a "ObserverRemoved" event
    *
    * @see Event_Dispatcher::removeObserver()
    */
   function removeObserver($callback, $nName = EVENT_DISPATCHER_GLOBAL, $class = null)
{
       $this->post($this, 'ObserverRemoved');
       parent::removeObserver($callback, $nName, $class);
} } -Philippe

« previous php.pear.dev (#36453) next »