[ Index ] |
|
Code source de Typo3 4.1.3 |
1 <?php 2 /* ************************************************************** 3 * Copyright notice 4 * 5 * (c) webservices.nl 6 * (c) 2006 Karsten Dambekalns <karsten@typo3.org> 7 * All rights reserved 8 * 9 * This script is part of the TYPO3 project. The TYPO3 project is 10 * free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * The GNU General Public License can be found at 16 * http://www.gnu.org/copyleft/gpl.html. 17 * A copy is found in the textfile GPL.txt and important notices to the license 18 * from the author is found in LICENSE.txt distributed with these scripts. 19 * 20 * 21 * This script is distributed in the hope that it will be useful, 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * GNU General Public License for more details. 25 * 26 * This copyright notice MUST APPEAR in all copies of the script! 27 ***************************************************************/ 28 /* $Id: class.em_soap.php 1421 2006-04-10 09:27:15Z mundaun $ */ 29 30 /** 31 * Enter description here... 32 * 33 */ 34 class em_soap { 35 /** 36 * valid options passed to the constructor : 37 * wsdl : The WSDL location, can be a local file location or 38 * an URL. 39 * soapoptions : Associative array of SOAP options to be passed to 40 * the SOAP implementation constructor, only used for 41 * the phpsoap implement. 42 * authentication : method of authentication : 43 * 'headers' soap headers are used 44 * 'prefix' function prefixes are used 45 * prefix : optional prefix to be put in front of all methods. 46 * implementation : Which type of soap implementation to use : 47 * 'detect' automatically detect an implementation. 48 * 'phpsoap' PHP builtin SOAP module 49 * <http://www.php.net/manual/en/ref.soap.php> 50 * 'nusoap' NuSOAP class 51 * <http://dietrich.ganx4.com/nusoap> 52 * 'pearsoap' PEAR SOAP class 53 * <http://pear.php.net/package/SOAP> 54 * format : Which type of return structure : 55 * 'object' PHP objects 56 * 'array' PHP arrays, default 57 */ 58 var $options = array(); 59 var $client = false; 60 var $error = false; 61 62 var $username = false; 63 var $password = false; 64 var $reactid = false; 65 66 /** 67 * Enter description here... 68 * 69 * @param array $options 70 * @param string $username 71 * @param string $password 72 * @return [type] ... 73 */ 74 function init($options=false, $username=false, $password=false) { 75 if ($username !== false) { 76 if ($password === false) { 77 $this->reactid = $username; 78 } else { 79 $this->username = $username; 80 $this->password = $password; 81 } 82 } 83 84 if (!$options['implementation'] || $options['implementation'] == 'detect') { 85 if (defined('SOAP_1_2')) { 86 $options['implementation'] = 'phpsoap'; 87 } elseif (class_exists('soapclient')) { 88 $options['implementation'] = 'nusoap'; 89 } elseif (class_exists('SOAP_Client')) { 90 $options['implementation'] = 'pearsoap'; 91 } 92 } 93 94 $options['format'] = $options['format'] == 'object' ? 'object' : 'array'; 95 96 if ($options !== false) { 97 $this->options = (array)$options; 98 } 99 100 switch ($this->options['implementation']) { 101 case 'nusoap': 102 $this->client =& new soapclient($this->options['wsdl'], true); 103 $this->client->getProxy(); 104 break; 105 case 'pearsoap': 106 $this->client =& new SOAP_Client($this->options['wsdl'], true); 107 break; 108 case 'phpsoap': 109 $this->client =& new SoapClient($options['wsdl'],(array)$options['soapoptions']); 110 break; 111 default: 112 $this->client = false; 113 } 114 } 115 116 /** 117 * Enter description here... 118 * 119 * @param string $username 120 * @param string $password 121 * @return mixed false on failure, $reactid on success 122 */ 123 function login($username, $password) { 124 $reactid = $this->call('login', array('username' => $username, 'password' => $password)); 125 126 if ($this->error) { 127 return false; 128 } 129 130 $this->reactid = $reactid; 131 $this->username = $username; 132 $this->password = false; 133 134 return $reactid; 135 } 136 137 /** 138 * Enter description here... 139 * 140 * @return unknown 141 */ 142 function logout() { 143 $this->call('logout'); 144 $this->reactid = false; 145 if ($this->error) { 146 return false; 147 } 148 return true; 149 } 150 151 152 /** 153 * Enter description here... 154 * 155 * @param unknown_type $func 156 * @param unknown_type $param 157 * @param unknown_type $username 158 * @param unknown_type $password 159 * @return unknown 160 */ 161 function call($func, $param=array(), $username=false, $password=false) { 162 if (!$this->client) { 163 $this->error = "Error in Webservices.class.php: No soap client implementation found. ". 164 "Make sure a SOAP library such as 'NuSoap.php' is included."; 165 return false; 166 } 167 168 if ($username !== false) { 169 if ($password === false) { 170 $this->reactid = $username; 171 } else { 172 $this->username = $username; 173 $this->password = $password; 174 } 175 } 176 177 if ($this->options['authentication'] == 'prefix') { 178 $param = array_merge(array('reactid' => $this->reactid), $param); 179 } 180 181 if ($this->options['prefix']) { 182 $func = $this->options['prefix'].ucfirst($func); 183 } 184 185 $this->error = false; 186 187 switch ($this->options['implementation']) { 188 case 'nusoap' : return $this->callNuSOAP($func, $param); break; 189 case 'pearsoap' : return $this->callPearSOAP($func, $param); break; 190 case 'phpsoap' : return $this->callPhpSOAP($func, $param); break; 191 } 192 193 return false; 194 } 195 196 /** 197 * Enter description here... 198 * 199 * @param unknown_type $func 200 * @param unknown_type $param 201 * @return unknown 202 */ 203 function callPhpSOAP($func, $param) { 204 $header = null; 205 if ($this->options['authentication'] == 'headers') { 206 if ($this->reactid) { 207 $header =& new SoapHeader( 208 '','HeaderAuthenticate', 209 (object)array('reactid' => $this->reactid), 1 210 ); 211 } elseif ($this->username && $this->password) { 212 $header =& new SoapHeader( 213 '','HeaderLogin', 214 (object)array( 215 'username' => $this->username, 216 'password' => $this->password 217 ), 1 218 ); 219 $this->password = false; 220 } 221 } 222 223 $result = $this->client->__soapCall($func, $param, NULL, $header); 224 225 if (is_soap_fault($result)) { 226 $this->error = $result; 227 return false; 228 } 229 230 if (is_a($this->client->headersIn['HeaderAuthenticate'],'stdClass')) { 231 $this->reactid = $this->client->headersIn['HeaderAuthenticate']->reactid; 232 } 233 234 return $this->options['format'] == 'object' ? $result : $this->object2array($result); 235 } 236 237 /** 238 * Enter description here... 239 * 240 * @param unknown_type $func 241 * @param unknown_type $param 242 * @return unknown 243 */ 244 function callPearSOAP($func,$param) { 245 if ($this->options['authentication'] == 'headers') { 246 if ($this->reactid) { 247 $this->client->addHeader( 248 new SOAP_Header( 249 'HeaderAuthenticate', NULL, 250 array('reactid' => $this->reactid), 1 251 ) 252 ); 253 } elseif ($this->username && $this->password) { 254 $this->client->addHeader( 255 new SOAP_Header( 256 'HeaderLogin', NULL, 257 array( 258 'username' => $this->username, 259 'password' => $this->password 260 ), 1 261 ) 262 ); 263 $this->password = false; 264 } 265 } 266 267 268 $result = $this->client->call($func, $param); 269 270 if (PEAR::isError($result)) { 271 $this->error = $result; 272 return false; 273 } 274 275 if (is_a($this->client->headersIn['HeaderAuthenticate'],'stdClass')) { 276 $this->reactid = $this->client->headersIn['HeaderAuthenticate']->reactid; 277 } 278 279 return $this->options['format'] == 'object' ? $result : $this->object2array($result); 280 } 281 282 /** 283 * Enter description here... 284 * 285 * @param unknown_type $func 286 * @param unknown_type $param 287 * @return unknown 288 */ 289 function callNuSOAP($func,$param) { 290 $header = false; 291 if ($this->options['authentication'] == 'headers') { 292 if ($this->reactid) { 293 $header = ( 294 "<HeaderAuthenticate SOAP-ENV:mustUnderstand='1'>". 295 "<reactid>".htmlspecialchars($this->reactid)."</reactid>". 296 "</HeaderAuthenticate>" 297 ); 298 } elseif ($this->username && $this->password) { 299 $header = ( 300 "<HeaderLogin SOAP-ENV:mustUnderstand='1'>". 301 "<username>".htmlspecialchars($this->username)."</username>". 302 "<password>".htmlspecialchars($this->password)."</password>". 303 "</HeaderLogin>" //HeaderLogin 304 ); 305 $this->password = false; 306 } 307 } 308 309 $result = $this->client->call($func, $param, false, false, $header); 310 311 if ($this->error = $this->client->getError()) { 312 return false; 313 } 314 315 // nusoap header support is very limited 316 $headers = $this->client->getHeaders(); 317 $matches = array(); 318 if (preg_match('~<([a-z0-9]+:)?reactid[^>]*>([^<]*)</([a-z0-9]+:)?reactid>~is', $headers, $matches)) { 319 $this->reactid = $matches[2]; 320 } 321 322 return $this->options['format'] == 'object' ? $this->array2object($result) : $result; 323 } 324 325 /** 326 * Enter description here... 327 * 328 * @param unknown_type $object 329 * @return unknown 330 */ 331 function object2array($object) { 332 if (!is_object($object) && !is_array($object)) { 333 return $object; 334 } 335 336 $array = (array)$object; 337 foreach ($array as $key => $value) { 338 $array[$key] = $this->object2array($value); 339 } 340 return $array; 341 } 342 343 /** 344 * Enter description here... 345 * 346 * @param unknown_type $array 347 * @return unknown 348 */ 349 function array2object($array) { 350 if (!is_array($array)) { 351 return $array; 352 } 353 354 foreach ($array as $key => $value) { 355 $array[$key] = $this->array2object($value); 356 } 357 return (object)$array; 358 } 359 360 /** 361 * Enter description here... 362 * 363 * @return unknown 364 */ 365 function lastRequest() { 366 switch ($this->options['implementation']) { 367 case 'nusoap' : return $this->client->request; break; 368 case 'pearsoap' : return $this->client->__getlastrequest(); break; 369 case 'phpsoap' : return $this->client->__getLastRequest(); break; 370 } 371 372 return false; 373 } 374 375 /** 376 * Enter description here... 377 * 378 * @return unknown 379 */ 380 function lastResponse() { 381 switch ($this->options['implementation']) { 382 case 'nusoap' : return $this->client->response; break; 383 case 'pearsoap' : return $this->client->__getlastresponse(); break; 384 case 'phpsoap' : return $this->client->__getLastResponse(); break; 385 } 386 387 return false; 388 } 389 390 /** 391 * Enter description here... 392 * 393 * @return unknown 394 */ 395 function getFunctions() { 396 switch ($this->options['implementation']) { 397 case 'nusoap' : return array_keys($this->client->operations); break; 398 case 'pearsoap' : return false; break; 399 case 'phpsoap' : return $this->client->__getFunctions(); break; 400 } 401 402 return false; 403 } 404 } 405 406 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Nov 25 17:13:16 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |