| [ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /* 3 4 SOAPx4 5 by Dietrich Ayala (C) 2001 dietrich@ganx4.com 6 7 This project began based on code from the 2 projects below, 8 and still contains some original code. The licenses of both must be respected. 9 10 XML-RPC for PHP 11 originally by Edd Dumbill (C) 1999-2000 12 13 SOAP for PHP 14 by Victor Zou (C) 2000-2001 <victor@gigaideas.com.cn> 15 16 */ 17 18 /* changelog: 19 2001-07-04 20 - abstract type system to support either 1999 or 2001 schema (arg, typing still needs much 21 solidification.) 22 - implemented proxy support, based on sample code from miles lott <milos@speakeasy.net> 23 - much general cleanup of code & cleaned out what was left of original xml-rpc/gigaideas code 24 - implemented a transport argument into send() that allows you to specify different transports 25 (assuming you have implemented the function, and added it to the conditional statement in send() 26 - abstracted the determination of charset in Content-type header 27 2001-07-5 28 - fixed more weird type/namespace issues 29 */ 30 31 // $path can be a complete endpoint url, with the other parameters left blank: 32 // $soap_client = new soap_client("http://path/to/soap/server"); 33 34 /* $Id: class.soapmsg.inc.php 11430 2003-08-28 14:31:11Z ralfbecker $ */ 35 36 // soap message class 37 class soapmsg 38 { 39 // params is an array of soapval objects 40 function soapmsg($method,$params,$method_namespace='http://testuri.org',$new_namespaces=False) 41 { 42 // globalize method namespace 43 $GLOBALS['methodNamespace'] = $method_namespace; 44 $namespaces = $GLOBALS['namespaces']; 45 46 // make method struct 47 $this->value = CreateObject('phpgwapi.soapval',$method,"struct",$params,$method_namespace); 48 if(is_array($new_namespaces)) 49 { 50 $i = count($namespaces); 51 @reset($new_namespaces); 52 while(list($null,$v) = @each($new_namespaces)) 53 /* foreach($new_namespaces as $v) */ 54 { 55 $namespaces[$v] = 'ns' . $i++; 56 } 57 $this->namespaces = $namespaces; 58 } 59 $this->payload = ''; 60 $this->debug_flag = True; 61 $this->debug_str = "entering soapmsg() with soapval ".$this->value->name."\n"; 62 } 63 64 function make_envelope($payload) 65 { 66 $namespaces = $GLOBALS['namespaces']; 67 @reset($namespaces); 68 while(list($k,$v) = @each($namespaces)) 69 /* foreach($namespaces as $k => $v) */ 70 { 71 $ns_string .= " xmlns:$v=\"$k\""; 72 } 73 return "<SOAP-ENV:Envelope $ns_string SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" 74 . $payload . "</SOAP-ENV:Envelope>\n"; 75 } 76 77 function make_body($payload) 78 { 79 return "<SOAP-ENV:Body>\n" . $payload . "</SOAP-ENV:Body>\n"; 80 } 81 82 function createPayload() 83 { 84 $value = $this->value; 85 $payload = $this->make_envelope($this->make_body($value->serialize())); 86 $this->debug($value->debug_str); 87 $payload = "<?xml version=\"1.0\"?>\n".$payload; 88 if($this->debug_flag) 89 { 90 $payload .= $this->serializeDebug(); 91 } 92 $this->payload = str_replace("\n","\r\n", $payload); 93 } 94 95 function serialize() 96 { 97 if($this->payload == '') 98 { 99 $this->createPayload(); 100 return $this->payload; 101 } 102 else 103 { 104 return $this->payload; 105 } 106 } 107 108 // returns a soapval object 109 function parseResponse($data) 110 { 111 $this->debug("Entering parseResponse()"); 112 //$this->debug(" w/ data $data"); 113 // strip headers here 114 //$clean_data = ereg_replace("\r\n","\n", $data); 115 if(ereg("^.*\r\n\r\n<",$data)) 116 { 117 $this->debug("found proper seperation of headers and document"); 118 $this->debug("getting rid of headers, stringlen: ".strlen($data)); 119 $clean_data = ereg_replace("^.*\r\n\r\n<","<", $data); 120 $this->debug("cleaned data, stringlen: ".strlen($clean_data)); 121 } 122 else 123 { 124 // return fault 125 return CreateObject('phpgwapi.soapval', 126 'fault', 127 'SOAPStruct', 128 Array( 129 CreateObject('phpgwapi.soapval','faultcode','string','SOAP-MSG'), 130 CreateObject('phpgwapi.soapval','faultstring','string','HTTP Error'), 131 CreateObject('phpgwapi.soapval','faultdetail','string','HTTP headers were not immediately followed by \'\r\n\r\n\'') 132 ) 133 ); 134 } 135 /* 136 // if response is a proper http response, and is not a 200 137 if(ereg("^HTTP",$clean_data) && !ereg("200$", $clean_data)) 138 { 139 // get error data 140 $errstr = substr($clean_data, 0, strpos($clean_data, "\n")-1); 141 // return fault 142 return CreateObject('phpgwapi.soapval', 143 "fault", 144 "SOAPStruct", 145 array( 146 CreateObject('phpgwapi.soapval',"faultcode","string","SOAP-MSG"), 147 CreateObject('phpgwapi.soapval',"faultstring","string","HTTP error") 148 ) 149 ); 150 } 151 */ 152 $this->debug("about to create parser instance w/ data: $clean_data"); 153 // parse response 154 $response = CreateObject('phpgwapi.soap_parser',$clean_data); 155 // return array of parameters 156 $ret = $response->get_response(); 157 $this->debug($response->debug_str); 158 return $ret; 159 } 160 161 // dbg 162 function debug($string) 163 { 164 if($this->debug_flag) 165 { 166 $this->debug_str .= "$string\n"; 167 } 168 } 169 170 // preps debug data for encoding into soapmsg 171 function serializeDebug() 172 { 173 if($this->debug_flag) 174 { 175 return "<!-- DEBUG INFO:\n".$this->debug_str."-->\n"; 176 } 177 else 178 { 179 return ''; 180 } 181 } 182 } 183 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |