PEIP_ABS_Message_Handler.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 
00021 abstract class PEIP_ABS_Message_Handler 
00022     implements PEIP_INF_Handler {
00023     
00024     protected 
00025         $inputChannel;
00026         
00027         
00028     
00034     public function handle($message){
00035         return $this->doHandle($message);
00036     }
00037 
00038     
00044     public function setInputChannel(PEIP_INF_Channel $inputChannel){
00045         $this->doSetInputChannel($inputChannel);
00046         return $this;
00047     }
00048 
00049     
00055     protected function doSetInputChannel(PEIP_INF_Channel $inputChannel){
00056         $this->inputChannel = $inputChannel;    
00057         $messageHandler = $this;
00058         if($inputChannel instanceof PEIP_INF_Subscribable_Channel){
00059             $getMessage = function ($object){
00060                 return $object;
00061             };  
00062             $linkChannel = function($handler) use ($messageHandler){
00063                 $messageHandler->getInputChannel()->subscribe($handler);    
00064             };              
00065         }else{          
00066             $getMessage = function ($object){
00067                 return $object->getContent()->receive();
00068             };  
00069             $linkChannel = function($handler) use ($messageHandler){
00070                 $messageHandler->getInputChannel()->connect('postSend', $handler);  
00071             };  
00072         }   
00073         $handling = function($object) use ($messageHandler, $getMessage){
00074             $message = $getMessage($object);
00075             if(!is_object($message)){ 
00076                 throw new Exception('Could not get Message from Channel');
00077             }               
00078             $messageHandler->handle($message);          
00079         };          
00080         $handler = new PEIP_Callable_Message_Handler($handling);
00081         $linkChannel($handler); 
00082     }
00083     
00084     
00085     
00090     public function getInputChannel(){
00091         return $this->inputChannel;
00092     }   
00093     
00094     
00100     abstract protected function doHandle(PEIP_INF_Message $message);
00101     
00102 }
00103 

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