_observerId = uniqid(rand()); $this->_observers[$event][$obj->_observerId] = &$obj; } /** * Attaches an object to the class listening for any event, * The object will be notified when any event occurs in the derived class * * @param object &$obj * @return mixed * @access public */ function attach_all(&$obj) { if (!is_object($obj)) { return false; } $obj->_observerId = uniqid(rand()); $this->_observers['all'][$obj->_observerId] = &$obj; } /** * Detaches an observer from the class * * @param object &$obj * @return void * @access public */ function dettach(&$obj) { if (isset($this->_observers[$obj->_observerId])) { unset($this->_observers[$obj->_observerId]); } } /** * Notifies objects of an event. This is called in the methods of the derived class that want to notify some event * * @access protected * @param string $event * @param string $msg * @return void */ function notify_all($event, $msg) { //reset($this->_observers[$event]); if(isset($this->_observers[$event])) { foreach ($this->_observers[$event] as $observer) { $observer->notify($event,$msg); } } if(isset($this->_observers['all'])) { foreach ($this->_observers['all'] as $observer) { $observer->notify($event,$msg); } } } } ?>