PEIP_Iterating_Dispatcher.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_Iterating_Dispatcher  
00023     implements PEIP_INF_Dispatcher {
00024 
00025     protected $listeners;
00026 
00027     
00033     public function __construct(ArrayIterator $listenerIterator = NULL){
00034         $this->listeners = $iterator ? $iterator : new ArrayIterator;
00035     }
00036     
00049     public function connect(PEIP_INF_Handler $listener){
00050     $this->listeners[] = $listener;
00051   }
00052 
00067     public function disconnect(PEIP_INF_Handler $listener){
00068     foreach ($this->listeners as $i => $callable){
00069       if ($listener === $callable){
00070         unset($this->listeners[$name][$i]);
00071       }
00072     }
00073   }
00074     
00075 
00088     public function hasListeners()
00089   {
00090     return (boolean) $this->listeners->count();
00091   }
00092 
00106     public function notify($subject){
00107         if($this->hasListeners()){
00108             if(!$this->listeners->valid()){
00109                 $this->listeners->rewind(); 
00110             }
00111             $this->listeners->current()->handle($subject);
00112             $this->listeners->next();           
00113         }         
00114     }
00115 
00116   
00117   
00130     public function getListeners(){
00131     return $this->listeners;
00132   }
00133     
00134 }

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