Server.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Shane Caraveo <Shane@Caraveo.com> Port to PEAR and more |
  17. // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: Server.php,v 1.44.2.1 2003/12/20 21:21:59 sklar Exp $
  21. //
  22. require_once 'SOAP/Base.php';
  23. require_once 'SOAP/Fault.php';
  24. require_once 'SOAP/Parser.php';
  25. require_once 'SOAP/Value.php';
  26. require_once 'SOAP/WSDL.php';
  27. $soap_server_fault = null;
  28. function SOAP_ServerErrorHandler($errno, $errmsg, $filename, $linenum, $vars) {
  29. global $soap_server_fault;
  30. $detail = "Errno: $errno\nFilename: $filename\nLineno: $linenum\n";
  31. // XXX very strange behaviour with error handling if we =& here.
  32. $soap_server_fault = new SOAP_Fault($errmsg, 'Server', 'PHP', $detail);
  33. }
  34. /**
  35. * SOAP::Server
  36. * SOAP Server Class
  37. *
  38. * originaly based on SOAPx4 by Dietrich Ayala http://dietrich.ganx4.com/soapx4
  39. *
  40. * @access public
  41. * @version $Id: Server.php,v 1.44.2.1 2003/12/20 21:21:59 sklar Exp $
  42. * @package SOAP::Client
  43. * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
  44. * @author Dietrich Ayala <dietrich@ganx4.com> Original Author
  45. */
  46. class SOAP_Server extends SOAP_Base
  47. {
  48. /**
  49. *
  50. * @var array
  51. */
  52. var $dispatch_map = array(); // create empty dispatch map
  53. var $dispatch_objects = array();
  54. var $soapobject = NULL;
  55. var $call_methodname = NULL;
  56. var $callHandler = NULL;
  57. var $callValidation = true;
  58. /**
  59. *
  60. * @var string
  61. */
  62. var $headers = '';
  63. /**
  64. *
  65. * @var string
  66. */
  67. var $request = '';
  68. /**
  69. *
  70. * @var string XML-Encoding
  71. */
  72. var $xml_encoding = SOAP_DEFAULT_ENCODING;
  73. var $response_encoding = 'UTF-8';
  74. var $result = 'successful'; // for logging interop results to db
  75. var $endpoint = ''; // the uri to ME!
  76. var $service = ''; //soapaction header
  77. var $method_namespace = NULL;
  78. var $__options = array('use'=>'encoded','style'=>'rpc','parameters'=>0);
  79. function SOAP_Server($options=NULL) {
  80. ini_set('track_errors',1);
  81. parent::SOAP_Base('Server');
  82. if (is_array($options)) {
  83. if (isset($options['use']))
  84. $this->__options['use'] = $options['use'];
  85. if (isset($options['style']))
  86. $this->__options['style'] = $options['style'];
  87. if (isset($options['parameters']))
  88. $this->__options['parameters'] = $options['parameters'];
  89. }
  90. $this->_section5 = TRUE; // assume we encode with section 5
  91. if ($this->__options['use']=='literal') $this->_section5 = FALSE;
  92. }
  93. function _getContentEncoding($content_type)
  94. {
  95. // get the character encoding of the incoming request
  96. // treat incoming data as UTF-8 if no encoding set
  97. $this->xml_encoding = 'UTF-8';
  98. if (strpos($content_type,'=')) {
  99. $enc = strtoupper(str_replace('"',"",substr(strstr($content_type,'='),1)));
  100. if (!in_array($enc, $this->_encodings)) {
  101. return FALSE;
  102. }
  103. $this->xml_encoding = $enc;
  104. }
  105. return TRUE;
  106. }
  107. // parses request and posts response
  108. function service($data, $endpoint = '', $test = FALSE)
  109. {
  110. $response = NULL;
  111. $attachments = array();
  112. $headers = array();
  113. $useEncoding = 'DIME';
  114. // figure out our endpoint
  115. $this->endpoint = $endpoint;
  116. if (!$test && !$this->endpoint) {
  117. // we'll try to build our endpoint
  118. $this->endpoint = 'http://'.$_SERVER['SERVER_NAME'];
  119. if ($_SERVER['SERVER_PORT']) $this->endpoint .= ':'.$_SERVER['SERVER_PORT'];
  120. $this->endpoint .= $_SERVER['SCRIPT_NAME'];
  121. }
  122. // get the character encoding of the incoming request
  123. // treat incoming data as UTF-8 if no encoding set
  124. if (isset($_SERVER['CONTENT_TYPE'])) {
  125. if (strcasecmp($_SERVER['CONTENT_TYPE'],'application/dime')==0) {
  126. $this->_decodeDIMEMessage($data,$headers,$attachments);
  127. $useEncoding = 'DIME';
  128. } else if (stristr($_SERVER['CONTENT_TYPE'],'multipart/related')) {
  129. // this is a mime message, lets decode it.
  130. $data = 'Content-Type: '.stripslashes($_SERVER['CONTENT_TYPE'])."\r\n\r\n".$data;
  131. $this->_decodeMimeMessage($data,$headers,$attachments);
  132. $useEncoding = 'Mime';
  133. }
  134. if (!isset($headers['content-type'])) {
  135. $headers['content-type'] = stripslashes($_SERVER['CONTENT_TYPE']);
  136. }
  137. if (!$this->fault &&
  138. !$this->_getContentEncoding($headers['content-type'])) {
  139. $this->xml_encoding = SOAP_DEFAULT_ENCODING;
  140. // an encoding we don't understand, return a fault
  141. $this->_raiseSoapFault('Unsupported encoding, use one of ISO-8859-1, US-ASCII, UTF-8','','','Server');
  142. }
  143. }
  144. // if this is not a POST with Content-Type text/xml, try to return a WSDL file
  145. if (!$this->fault && !$test && ($_SERVER['REQUEST_METHOD'] != 'POST' ||
  146. strncmp($headers['content-type'],'text/xml',8) != 0)) {
  147. // this is not possibly a valid soap request, try to return a WSDL file
  148. $this->_raiseSoapFault("Invalid SOAP request, must be POST with content-type: text/xml, got: ".(isset($headers['content-type'])?$headers['content-type']:'Nothing!'),'','','Server');
  149. }
  150. if (!$this->fault) {
  151. // $response is a soap_msg object
  152. $soap_msg = $this->parseRequest($data, $attachments);
  153. // handle Mime or DIME encoding
  154. // XXX DIME Encoding should move to the transport, do it here for now
  155. // and for ease of getting it done
  156. if (count($this->__attachments)) {
  157. if ($useEncoding == 'Mime') {
  158. $soap_msg = $this->_makeMimeMessage($soap_msg);
  159. } else {
  160. // default is dime
  161. $soap_msg = $this->_makeDIMEMessage($soap_msg);
  162. $header['Content-Type'] = 'application/dime';
  163. }
  164. if (PEAR::isError($soap_msg)) {
  165. return $this->raiseSoapFault($soap_msg);
  166. }
  167. }
  168. if (is_array($soap_msg)) {
  169. $response = $soap_msg['body'];
  170. if (count($soap_msg['headers'])) {
  171. $header = $soap_msg['headers'];
  172. }
  173. } else {
  174. $response = $soap_msg;
  175. }
  176. }
  177. // make distinction between the different choice of installation,
  178. // running php as cgi or as a module
  179. if(stristr(php_sapi_name(),'cgi')==0)
  180. $hdrs_type = 'Status:';
  181. else
  182. $hdrs_type = 'HTTP/1.1';
  183. if ($this->fault) {
  184. $hdrs = "$hdrs_type 500 Soap Fault\r\n";
  185. $response = $this->fault->message();
  186. } else {
  187. $hdrs = "$hdrs_type 200 OK\r\n";
  188. }
  189. header($hdrs);
  190. $header['Server'] = SOAP_LIBRARY_NAME;
  191. if (!isset($header['Content-Type']))
  192. $header['Content-Type'] = "text/xml; charset=$this->response_encoding";
  193. $header['Content-Length'] = strlen($response);
  194. reset($header);
  195. foreach ($header as $k => $v) {
  196. header("$k: $v");
  197. $hdrs .= "$k: $v\r\n";
  198. }
  199. $this->response = $hdrs . "\r\n" . $response;
  200. print $response;
  201. }
  202. function &callMethod($methodname, &$args) {
  203. global $soap_server_fault;
  204. $soap_server_fault = null;
  205. if ($this->callHandler) {
  206. return @call_user_func_array($this->callHandler,array($methodname,$args));
  207. }
  208. set_error_handler('SOAP_ServerErrorHandler');
  209. if ($args) {
  210. // call method with parameters
  211. if (isset($this->soapobject) && is_object($this->soapobject)) {
  212. $ret = @call_user_func_array(array(&$this->soapobject, $methodname),$args);
  213. } else {
  214. $ret = @call_user_func_array($methodname,$args);
  215. }
  216. } else {
  217. // call method w/ no parameters
  218. if (is_object($this->soapobject)) {
  219. $ret = @call_user_func(array(&$this->soapobject, $methodname));
  220. } else {
  221. $ret = @call_user_func($methodname);
  222. }
  223. }
  224. restore_error_handler();
  225. return is_null($soap_server_fault) ? $ret : $soap_server_fault;
  226. }
  227. // create soap_val object w/ return values from method, use method signature to determine type
  228. function buildResult(&$method_response, &$return_type, $return_name='return', $namespace = '')
  229. {
  230. if (gettype($method_response) == 'object' && is_a($method_response,'soap_value')) {
  231. $return_val = array($method_response);
  232. } else {
  233. if (is_array($return_type) && is_array($method_response)) {
  234. $i = 0;
  235. foreach ($return_type as $key => $type) {
  236. if (is_numeric($key)) $key = 'item';
  237. if (is_a($method_response[$i],'soap_value')) {
  238. $return_val[] = $method_response[$i++];
  239. } else {
  240. $qn =& new QName($key, $namespace);
  241. $return_val[] =& new SOAP_Value($qn->fqn(),$type,$method_response[$i++]);
  242. }
  243. }
  244. } else {
  245. if (is_array($return_type)) {
  246. $keys = array_keys($return_type);
  247. if (!is_numeric($keys[0])) $return_name = $keys[0];
  248. $values = array_values($return_type);
  249. $return_type = $values[0];
  250. }
  251. $qn =& new QName($return_name, $namespace);
  252. $return_val = array();
  253. $return_val[] =& new SOAP_Value($qn->fqn(),$return_type,$method_response);
  254. }
  255. }
  256. return $return_val;
  257. }
  258. function parseRequest($data = '', $attachments = null)
  259. {
  260. // parse response, get soap parser obj
  261. $parser =& new SOAP_Parser($data,$this->xml_encoding,$attachments);
  262. // if fault occurred during message parsing
  263. if ($parser->fault) {
  264. $this->fault = $parser->fault;
  265. return null;
  266. }
  267. //*******************************************************
  268. // handle message headers
  269. $request_headers = $parser->getHeaders();
  270. $header_results = array();
  271. if ($request_headers) {
  272. if (!is_a($request_headers,'soap_value')) {
  273. $this->_raiseSoapFault("parser did not return SOAP_Value object: $request_headers",'','','Server');
  274. return null;
  275. }
  276. if ($request_headers->value) {
  277. // handle headers now
  278. foreach ($request_headers->value as $header_val) {
  279. $f_exists = $this->validateMethod($header_val->name, $header_val->namespace);
  280. # XXX this does not take into account message routing yet
  281. $myactor = (
  282. !$header_val->actor ||
  283. $header_val->actor == 'http://schemas.xmlsoap.org/soap/actor/next' ||
  284. $header_val->actor == $this->endpoint);
  285. if (!$f_exists && $header_val->mustunderstand && $myactor) {
  286. $this->_raiseSoapFault("I don't understand header $header_val->name.",'','','MustUnderstand');
  287. return null;
  288. }
  289. // we only handle the header if it's for us
  290. $isok = $f_exists && $myactor;
  291. if ($isok) {
  292. # call our header now!
  293. $header_method = $header_val->name;
  294. $header_data = array($this->_decode($header_val));
  295. // if there are parameters to pass
  296. $hr =& $this->callMethod($header_method, $header_data);
  297. # if they return a fault, then it's all over!
  298. if (PEAR::isError($hr)) {
  299. $this->_raiseSoapFault($hr);
  300. return null;
  301. }
  302. $header_results[] = array_shift($this->buildResult($hr, $this->return_type, $header_method, $header_val->namespace));
  303. }
  304. }
  305. }
  306. }
  307. //*******************************************************
  308. // handle the method call
  309. // evaluate message, getting back a SOAP_Value object
  310. $this->call_methodname = $this->methodname = $parser->root_struct_name[0];
  311. // figure out the method_namespace
  312. $this->method_namespace = $parser->message[$parser->root_struct[0]]['namespace'];
  313. if ($this->_wsdl) {
  314. $this->_setSchemaVersion($this->_wsdl->xsd);
  315. $dataHandler = $this->_wsdl->getDataHandler($this->methodname,$this->method_namespace);
  316. if ($dataHandler)
  317. $this->call_methodname = $this->methodname = $dataHandler;
  318. $this->_portName = $this->_wsdl->getPortName($this->methodname);
  319. if (PEAR::isError($this->_portName)) {
  320. return $this->_raiseSoapFault($this->_portName);
  321. }
  322. $opData = $this->_wsdl->getOperationData($this->_portName, $this->methodname);
  323. if (PEAR::isError($opData)) {
  324. return $this->_raiseSoapFault($opData);
  325. }
  326. $this->__options['style'] = $opData['style'];
  327. $this->__options['use'] = $opData['output']['use'];
  328. $this->__options['parameters'] = $opData['parameters'];
  329. }
  330. // does method exist?
  331. if (!$this->methodname || !$this->validateMethod($this->methodname,$this->method_namespace)) {
  332. $this->_raiseSoapFault("method '{{$this->method_namespace}}$this->methodname' not defined in service",'','','Server');
  333. return NULL;
  334. }
  335. if (!$request_val = $parser->getResponse()) {
  336. return NULL;
  337. }
  338. if (!is_a($request_val,'soap_value')) {
  339. $this->_raiseSoapFault("parser did not return SOAP_Value object: $request_val",'','','Server');
  340. return NULL;
  341. }
  342. // verify that SOAP_Value objects in request match the methods signature
  343. if (!$this->verifyMethod($request_val)) {
  344. // verifyMethod creates the fault
  345. return NULL;
  346. }
  347. // need to set special error detection inside the value class
  348. // so as to differentiate between no params passed, and an error decoding
  349. $request_data = $this->__decodeRequest($request_val);
  350. if (PEAR::isError($request_data)) {
  351. return $this->_raiseSoapFault($request_data);
  352. }
  353. $method_response =& $this->callMethod($this->call_methodname, $request_data);
  354. if (PEAR::isError($method_response)) {
  355. $this->_raiseSoapFault($method_response);
  356. return null;
  357. }
  358. if ($this->__options['parameters'] || !$method_response || $this->__options['style']=='rpc') {
  359. // get the method result
  360. if (is_null($method_response))
  361. $return_val = NULL;
  362. else
  363. $return_val = $this->buildResult($method_response, $this->return_type);
  364. $qn =& new QName($this->methodname.'Response',$this->method_namespace);
  365. $methodValue =& new SOAP_Value($qn->fqn(), 'Struct', $return_val);
  366. } else {
  367. $methodValue =& $method_response;
  368. }
  369. return $this->_makeEnvelope($methodValue, $header_results, $this->response_encoding);
  370. }
  371. function &__decodeRequest($request,$shift=false)
  372. {
  373. if (!$request) return NULL;
  374. // check for valid response
  375. if (PEAR::isError($request)) {
  376. return $this->_raiseSoapFault($request);
  377. } else if (!is_a($request,'soap_value')) {
  378. return $this->_raiseSoapFault("Invalid data in server::__decodeRequest");
  379. }
  380. // decode to native php datatype
  381. $requestArray = $this->_decode($request);
  382. // fault?
  383. if (PEAR::isError($requestArray)) {
  384. return $this->_raiseSoapFault($requestArray);
  385. }
  386. if (is_object($requestArray)&& get_class($requestArray) == 'stdClass') {
  387. $requestArray = get_object_vars($requestArray);
  388. } else
  389. if ($this->__options['style']=='document') {
  390. $requestArray = array($requestArray);
  391. }
  392. if (is_array($requestArray)) {
  393. if (isset($requestArray['faultcode']) || isset($requestArray['SOAP-ENV:faultcode'])) {
  394. $faultcode = $faultstring = $faultdetail = $faultactor = '';
  395. foreach ($requestArray as $k => $v) {
  396. if (stristr($k,'faultcode')) $faultcode = $v;
  397. if (stristr($k,'faultstring')) $faultstring = $v;
  398. if (stristr($k,'detail')) $faultdetail = $v;
  399. if (stristr($k,'faultactor')) $faultactor = $v;
  400. }
  401. return $this->_raiseSoapFault($faultstring, $faultdetail, $faultactor, $faultcode);
  402. }
  403. // return array of return values
  404. if ($shift && count($requestArray) == 1) {
  405. return array_shift($requestArray);
  406. }
  407. return $requestArray;
  408. }
  409. return $requestArray;
  410. }
  411. function verifyMethod($request)
  412. {
  413. if (!$this->callValidation) return TRUE;
  414. //return true;
  415. $params = $request->value;
  416. // get the dispatch map if one exists
  417. $map = NULL;
  418. if (array_key_exists($this->methodname, $this->dispatch_map)) {
  419. $map = $this->dispatch_map[$this->methodname];
  420. } else if (isset($this->soapobject)) {
  421. if (method_exists($this->soapobject, '__dispatch')) {
  422. $map = $this->soapobject->__dispatch($this->methodname);
  423. } else if (method_exists($this->soapobject, $this->methodname)) {
  424. // no map, all public functions are soap functions
  425. return TRUE;
  426. }
  427. }
  428. if (!$map) {
  429. $this->_raiseSoapFault("soap request specified an unhandled method '$this->methodname'",'','','Client');
  430. return FALSE;
  431. }
  432. // if we aliased the soap method name to a php function,
  433. // change the call_method so we do the right thing.
  434. if (array_key_exists('alias',$map) && !empty($map['alias'])) {
  435. $this->call_methodname = $map['alias'];
  436. }
  437. // if there are input parameters required...
  438. if ($sig = $map['in']) {
  439. $this->input_value = count($sig);
  440. $this->return_type = $this->getReturnType($map['out']);
  441. if (is_array($params)) {
  442. // validate the number of parameters
  443. if (count($params) == count($sig)) {
  444. // make array of param types
  445. foreach ($params as $param) {
  446. $p[] = strtolower($param->type);
  447. }
  448. $sig_t = array_values($sig);
  449. // validate each param's type
  450. for($i=0; $i < count($p); $i++) {
  451. // type not match
  452. // if soap types do not match, we ok it if the mapped php types match
  453. // this allows using plain php variables to work (ie. stuff like Decimal would fail otherwise)
  454. // we only error if the types exist in our type maps, and they differ
  455. if (strcasecmp($sig_t[$i],$p[$i])!=0 &&
  456. (isset($this->_typemap[SOAP_XML_SCHEMA_VERSION][$sig_t[$i]]) &&
  457. strcasecmp($this->_typemap[SOAP_XML_SCHEMA_VERSION][$sig_t[$i]],$this->_typemap[SOAP_XML_SCHEMA_VERSION][$p[$i]])!=0)) {
  458. $param = $params[$i];
  459. $this->_raiseSoapFault("soap request contained mismatching parameters of name $param->name had type [{$p[$i]}], which did not match signature's type: [{$sig_t[$i]}], matched? ".(strcasecmp($sig_t[$i],$p[$i])),'','','Client');
  460. return false;
  461. }
  462. }
  463. return true;
  464. // oops, wrong number of paramss
  465. } else {
  466. $this->_raiseSoapFault("soap request contained incorrect number of parameters. method '$this->methodname' required ".count($sig).' and request provided '.count($params),'','','Client');
  467. return false;
  468. }
  469. // oops, no params...
  470. } else {
  471. $this->_raiseSoapFault("soap request contained incorrect number of parameters. method '$this->methodname' requires ".count($sig).' parameters, and request provided none','','','Client');
  472. return false;
  473. }
  474. // no params
  475. }
  476. // we'll try it anyway
  477. return true;
  478. }
  479. // get string return type from dispatch map
  480. function getReturnType($returndata)
  481. {
  482. if (is_array($returndata)) {
  483. if (count($returndata) > 1) {
  484. return $returndata;
  485. }
  486. $type = array_shift($returndata);
  487. return $type;
  488. }
  489. return false;
  490. }
  491. function validateMethod($methodname, $namespace = NULL)
  492. {
  493. unset($this->soapobject);
  494. if (!$this->callValidation) return TRUE;
  495. # no soap access to private functions
  496. if ($methodname[0] == '_') return FALSE;
  497. /* if it's in our function list, ok */
  498. if (array_key_exists($methodname, $this->dispatch_map) &&
  499. (!$namespace || !array_key_exists('namespace', $this->dispatch_map[$methodname]) ||
  500. $namespace == $this->dispatch_map[$methodname]['namespace'])) {
  501. if (array_key_exists('namespace', $this->dispatch_map[$methodname]))
  502. $this->method_namespace = $this->dispatch_map[$methodname]['namespace'];
  503. return TRUE;
  504. }
  505. /* if it's in an object, it's ok */
  506. if (isset($this->dispatch_objects[$namespace])) {
  507. $c = count($this->dispatch_objects[$namespace]);
  508. for ($i=0; $i < $c; $i++) {
  509. $obj =& $this->dispatch_objects[$namespace][$i];
  510. // if we have a dispatch map, and the function is not
  511. // in the dispatch map, then it is not callable!
  512. if (method_exists($obj, '__dispatch')) {
  513. if ($obj->__dispatch($methodname)) {
  514. $this->method_namespace = $namespace;
  515. $this->soapobject =& $obj;
  516. return TRUE;
  517. }
  518. } else
  519. if (method_exists($obj, $methodname)) {
  520. $this->method_namespace = $namespace;
  521. $this->soapobject =& $obj;
  522. return TRUE;
  523. }
  524. }
  525. }
  526. return FALSE;
  527. }
  528. function addObjectMap(&$obj, $namespace = null, $service_name = 'Default', $service_desc = '')
  529. {
  530. if (!$namespace) {
  531. if (isset($obj->namespace)) {
  532. // XXX a bit of backwards compatibility
  533. $namespace = $obj->namespace;
  534. } else {
  535. $this->_raiseSoapFault('No namespace provided for class!','','','Server');
  536. return false;
  537. }
  538. }
  539. if (!isset($this->dispatch_objects[$namespace])) {
  540. $this->dispatch_objects[$namespace] = array();
  541. }
  542. $this->dispatch_objects[$namespace][] =& $obj;
  543. // Create internal WSDL structures for object
  544. // XXX Because some internal workings of PEAR::SOAP decide whether to
  545. // do certain things by the presence or absence of _wsdl, we should
  546. // only create a _wsdl structure if we know we can fill it; if
  547. // __dispatch_map or __typedef for the object is missing, we should
  548. // avoid creating it. Later, when we are using PHP 5 introspection,
  549. // we will be able to make the data for all objects without any extra
  550. // information from the developers, and this condition should be
  551. // dropped.
  552. // XXX Known issue: if imported WSDL (bindWSDL) or another WSDL source
  553. // is used to add _wsdl structure information, then addObjectWSDL is
  554. // used, there is a high possibility of _wsdl data corruption;
  555. // therefore you should avoid using __dispatch_map/__typedef definitions
  556. // AND other WSDL data sources in the same service. We exclude classes
  557. // that don't have __typedefs to allow external WSDL files to be used
  558. // with classes with no internal type definitions (the types are defined
  559. // in the WSDL file). When addObjectWSDL is refactored to not cause
  560. // corruption, this restriction can be relaxed.
  561. // In summry, if you add an object with both a dispatch map and type
  562. // definitions, then previous WSDL file operation and type definitions
  563. // will be overwritten.
  564. if (isset($obj->__dispatch_map) && isset($obj->__typedef)) {
  565. $this->addObjectWSDL($obj, $namespace, $service_name, $service_desc);
  566. }
  567. return true;
  568. }
  569. // add a method to the dispatch map
  570. function addToMap($methodname, $in, $out, $namespace = NULL, $alias=NULL)
  571. {
  572. if (!function_exists($methodname)) {
  573. $this->_raiseSoapFault("error mapping function\n",'','','Server');
  574. return false;
  575. }
  576. $this->dispatch_map[$methodname]['in'] = $in;
  577. $this->dispatch_map[$methodname]['out'] = $out;
  578. $this->dispatch_map[$methodname]['alias'] = $alias;
  579. if ($namespace) $this->dispatch_map[$methodname]['namespace'] = $namespace;
  580. return true;
  581. }
  582. function setCallHandler($callHandler, $validation=true) {
  583. $this->callHandler = $callHandler;
  584. $this->callValidation = $validation;
  585. }
  586. /**
  587. * @deprecated use bindWSDL from now on
  588. */
  589. function bind($wsdl_url) {
  590. $this->bindWSDL($wsdl_url);
  591. }
  592. /**
  593. * @param string a url to a WSDL resource
  594. * @return void
  595. */
  596. function bindWSDL($wsdl_url) {
  597. // instantiate wsdl class
  598. $this->_wsdl =& new SOAP_WSDL($wsdl_url);
  599. if ($this->_wsdl->fault) {
  600. $this->_raiseSoapFault($this->_wsdl->fault);
  601. }
  602. }
  603. /**
  604. * @return void
  605. */
  606. function addObjectWSDL(&$wsdl_obj, $targetNamespace, $service_name, $service_desc = '') {
  607. if (!isset($this->_wsdl)) {
  608. $this->_wsdl =& new SOAP_WSDL;
  609. }
  610. $this->_wsdl->parseObject($wsdl_obj, $targetNamespace, $service_name, $service_desc);
  611. if ($this->_wsdl->fault) {
  612. $this->_raiseSoapFault($this->_wsdl->fault);
  613. }
  614. }
  615. }
  616. ?>