PEIP_Observable.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  * This file is part of the PEIP package.
00005  * (c) 2010 Timo Michna <timomichna/yahoo.de>
00006  * 
00007  * For the full copyright and license information, please view the LICENSE
00008  * file that was distributed with this source code.
00009  */
00010 
00022 class PEIP_Observable implements PEIP_INF_Observable {
00023 
00024     protected $observedObject;
00025     
00026     protected $observers = array();
00027 
00028     protected $hasChanged = false;
00029     
00030     
00036     public function __construct(object $observedObject){
00037         $this->observedObject = $observedObject;
00038     }
00039 
00040     
00046     public function addObserver(PEIP_INF_Observer $observer){
00047         $this->observers[] = $observer;     
00048     }
00049 
00050     
00056     public function deleteObserver(PEIP_INF_Observer $observer){
00057         foreach($this->observers as $key=>$obs){
00058             if($obs == $observer){
00059                 unset($this->observers[$key]);
00060                 return true;
00061             }
00062         }
00063     }
00064     
00065     
00071     public function notifyObservers(array $arguments = array()){
00072         if($this->hasChanged()){
00073             foreach($this->observers as $observer){
00074                 $observer->update($this->observedObject);
00075             }       
00076         }
00077     }
00078 
00079     
00084     public function countObservers(){
00085         return count($this->obeservers);
00086     }
00087     
00088     
00093     public function hasChanged(){
00094         return $this->hasChanged();
00095     }
00096     
00097     
00102     public function setChanged(){
00103         $this->hasChanged = true;
00104     }
00105 
00106     
00111     public function clearChanged(){
00112         $this->hasChanged = true;   
00113     }
00114 
00115 
00116 
00117 
00118 }

Generated on Mon Apr 12 11:39:00 2010 for PEIP by  doxygen 1.5.1