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 abstract class PEIP_ABS_Subscribable_Channel 00023 extends PEIP_ABS_Interceptable_Message_Channel 00024 implements PEIP_INF_Subscribable_Channel{ 00025 00026 protected $messageDispatcher; 00027 00028 00034 public function subscribe(PEIP_INF_Handler $handler){ 00035 $this->getMessageDispatcher()->connect($handler); 00036 $this->getInterceptorDispatcher()->notify('subscribe', array($this, $handler)); 00037 $this->doFireEvent('subscribe', array('SUBSCRIBER'=>$handler)); 00038 } 00039 00040 00046 public function unsubscribe(PEIP_INF_Handler $handler){ 00047 $this->getMessageDispatcher()->disconnect($handler); 00048 $this->getInterceptorDispatcher()->notify('unsubscribe', array($this, $handler)); 00049 $this->doFireEvent('unsubscribe', array('SUBSCRIBER'=>$handler)); 00050 } 00051 00052 00059 public function setMessageDispatcher(PEIP_INF_Dispatcher $dispatcher, $transferListeners = true){ 00060 if(isset($this->dispatcher) && $transferListeners){ 00061 foreach($this->dispatcher->getListeners() as $listener){ 00062 $dispatcher->connect($listener); 00063 $this->dispatcher->disconnect($listener); 00064 } 00065 } 00066 $this->dispatcher = $dispatcher; 00067 } 00068 00069 00074 public function getMessageDispatcher(){ 00075 return isset($this->dispatcher) ? $this->dispatcher : $this->dispatcher = new PEIP_Dispatcher; 00076 } 00077 00078 }