PEIP_Callable_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 
00022 class PEIP_Callable_Message_Handler 
00023     implements PEIP_INF_Handler {
00024 
00025     protected 
00026         $callable,
00027         $requiredParameters;
00028     
00029     
00035     public function __construct($callable){
00036         $this->callable = $callable;    
00037         $this->examineCallabe();
00038     }
00039 
00040     
00045     protected function examineCallabe(){
00046         if(is_callable($this->callable)){        
00047             if(is_array($this->callable)){
00048                 list($class, $method) =  $this->callable;
00049                 $static = !is_object($class);
00050                 $class = is_object($class) ? get_class($class) : (string)$class;
00051                 $reflectionClass = new ReflectionClass($class);
00052                 $reflectionFunc = $reflectionClass->getMethod($method);
00053                 if($static && !$reflectionFunc->isStatic()){
00054                     throw new InvalidArgumentException('Argument 1 passed to PEIP_Callable_Message_Handler::__construct is not an Callable: Method "'.$method.'" of class '.$class.' is not static.');                  
00055                 }
00056             }else{
00057                 $reflectionFunc = new ReflectionFunction($this->callable);  
00058             }
00059             $this->requiredParameters = $reflectionFunc->getNumberOfRequiredParameters();
00060         }else{
00061             throw new InvalidArgumentException('Argument 1 passed to PEIP_Callable_Message_Handler::__construct is not a Callable');
00062         }   
00063     }   
00064     
00065     
00073     public function handle($message, $channel = false, $sent = false){
00074         if(!is_object($message)){
00075             throw new InvalidArgumentException('Argument 1 passed to PEIP_Callable_Message_Handler::handle is not a Object');       
00076         }   
00077         try {
00078             return call_user_func_array($this->callable, array($message, $channel, $sent));
00079         }
00080         catch(Exception $e){
00081             throw new RuntimeException('Unable to call Callable: '.$e->getMessage());
00082         }   
00083     }   
00084 }

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