Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

Observable.php

00001 <?php
00004 
00015 class Observable {
00016   var $_observers=Array();
00017   
00018   function Observable() {
00019   
00020   }
00021   
00027   function attach($event, &$obj)
00028   {
00029     if (!is_object($obj)) {
00030         return false;
00031     }
00032     $obj->_observerId = uniqid(rand());
00033     $this->_observers[$event][$obj->_observerId] = &$obj;
00034   }
00035   
00040   function attach_all(&$obj)
00041   {
00042     if (!is_object($obj)) {
00043         return false;
00044     }
00045     $obj->_observerId = uniqid(rand());
00046     $this->_observers['all'][$obj->_observerId] = &$obj;
00047   }
00048   
00052   function dettach(&$obj)
00053   {
00054         if (isset($this->_observers[$obj->_observerId])) {
00055         unset($this->_observers[$obj->_observerId]);
00056     }
00057   }
00058   
00064   function notify_all($event, $msg)
00065   {
00066         //reset($this->_observers[$event]);
00067         if(isset($this->_observers[$event])) {
00068         foreach ($this->_observers[$event] as $observer) {
00069                 $observer->notify($event,$msg);
00070         }
00071     }
00072         if(isset($this->_observers['all'])) {
00073         foreach ($this->_observers['all'] as $observer) {
00074                 $observer->notify($event,$msg);
00075         }
00076     }
00077     
00078   } 
00079 
00080 }
00081 ?>

Generated on Mon Jun 7 16:37:37 2004 for Galaxia by doxygen 1.3.4