PEIP_Message_Builder.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_Message_Builder 
00023     implements 
00024         PEIP_INF_Message_Builder,
00025         PEIP_INF_Dedicated_Factory {
00026 
00027     protected $messageClass;
00028     
00029     protected $factory;
00030     
00031     protected $headers = array();
00032     
00033     protected  $payload;
00034     
00035     
00041     public function __construct($messageClass = 'PEIP_Generic_Message'){
00042         $this->messageClass = $messageClass;
00043         $this->factory = PEIP_Dedicated_Factory::getfromCallable(array($messageClass, 'build'));    
00044     }
00045 
00046     
00052     public function copyHeaders(array $headers){
00053         array_merge($this->headers, $headers);
00054         return $this;       
00055     }
00056     
00057     
00069     public function copyHeadersIfAbsent (array $headers){
00070         array_merge($headers, $this->headers);
00071         return $this;   
00072     }
00073     
00074     
00080     public function removeHeader($headerName){
00081         unset($this->header[$headerName]);
00082         return $this;
00083     }
00084     
00085     
00092     public function setHeader($headerName, $headerValue){
00093         $this->header[$headerName] = $headerValue;
00094         return $this;   
00095     }
00096     
00097     
00110     public function setHeaders(array $headers){
00111         $this->headers = $headers;
00112         return $this;   
00113     }
00114     
00115     
00121     public function build(array $arguments = array()){
00122         $this->copyHeaders($arguments);
00123         return PEIP_Generic_Builder::getInstance($this->messageClass)
00124             ->build(array($this->payload, new ArrayObject($this->headers)));        
00125     }
00126     
00127     
00133     public function setContent($payload){
00134         $this->payload = $payload;
00135         return $this;
00136     }
00137     
00138     public static function getInstance($messageClass = 'PEIP_Generic_Message'){
00139         return new  PEIP_Message_Builder($messageClass);
00140     }
00141     
00142     public static function createFromMessage(PEIP_INF_Message $message){
00143         return new PEIP_Message_Builder(get_class($message));
00144     }
00145 
00146     
00152     public function setMessageClass($messageClass){
00153         $this->messageClass = $messageClass;
00154     }
00155 
00156     
00161     public function getMessageClass(){
00162         return $this->messageClass;
00163     }       
00164     
00165 }

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