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_Router 00023 extends PEIP_Pipe { 00024 00025 protected $channelResolver; 00026 00027 00034 public function __construct(PEIP_INF_Channel_Resolver $channelResolver, PEIP_INF_Channel $inputChannel){ 00035 $this->channelResolver = $channelResolver; 00036 $this->setInputChannel($inputChannel); 00037 } 00038 00039 00045 public function setChannelResolver(PEIP_INF_Channel_Resolver $channelResolver){ 00046 $this->channelResolver = $channelResolver; 00047 } 00048 00049 00055 protected function doReply(PEIP_INF_Message $message){ 00056 $ch = $this->selectChannels($message); 00057 $channels = is_array($ch) ? $ch : array($ch); 00058 foreach($channels as $channel){ 00059 $this->setOutputChannel($this->resolveChannel($channel)); 00060 $this->replyMessage($message); 00061 } 00062 } 00063 00064 00070 protected function resolveChannel($channel){ 00071 if(!($channel instanceof PEIP_INF_Channel)){ 00072 $channel = $this->channelResolver->resolveChannelName($channel); 00073 if(!$channel){ 00074 throw new RuntimeException('Could not resolve Channel : '.$channel); 00075 } 00076 } 00077 return $channel; 00078 } 00079 00080 00086 abstract protected function selectChannels(PEIP_INF_Message $message); 00087 00088 00089 }