nusoap_xmlschema

Parses an XML Schema, allows access to it's data, other utility methods.

Defined (2)

The class is defined in the following location(s).

/lib/class.xmlschema.php  
  1. class nusoap_xmlschema extends nusoap_base { 
  2.  
  3. // files 
  4. var $schema = ''; 
  5. var $xml = ''; 
  6. // namespaces 
  7. var $enclosingNamespaces; 
  8. // schema info 
  9. var $schemaInfo = array(); 
  10. var $schemaTargetNamespace = ''; 
  11. // types, elements, attributes defined by the schema 
  12. var $attributes = array(); 
  13. var $complexTypes = array(); 
  14. var $complexTypeStack = array(); 
  15. var $currentComplexType = null; 
  16. var $elements = array(); 
  17. var $elementStack = array(); 
  18. var $currentElement = null; 
  19. var $simpleTypes = array(); 
  20. var $simpleTypeStack = array(); 
  21. var $currentSimpleType = null; 
  22. // imports 
  23. var $imports = array(); 
  24. // parser vars 
  25. var $parser; 
  26. var $position = 0; 
  27. var $depth = 0; 
  28. var $depth_array = array(); 
  29. var $message = array(); 
  30. var $defaultNamespace = array(); 
  31.  
  32. /** 
  33. * constructor 
  34. * @param string $schema schema document URI 
  35. * @param string $xml xml document URI 
  36. * @param string $namespaces namespaces defined in enclosing XML 
  37. * @access public 
  38. */ 
  39. function nusoap_xmlschema($schema='', $xml='', $namespaces=array()) { 
  40. parent::nusoap_base(); 
  41. $this->debug('nusoap_xmlschema class instantiated, inside constructor'); 
  42. // files 
  43. $this->schema = $schema; 
  44. $this->xml = $xml; 
  45.  
  46. // namespaces 
  47. $this->enclosingNamespaces = $namespaces; 
  48. $this->namespaces = array_merge($this->namespaces, $namespaces); 
  49.  
  50. // parse schema file 
  51. if($schema != '') { 
  52. $this->debug('initial schema file: '.$schema); 
  53. $this->parseFile($schema, 'schema'); 
  54.  
  55. // parse xml file 
  56. if($xml != '') { 
  57. $this->debug('initial xml file: '.$xml); 
  58. $this->parseFile($xml, 'xml'); 
  59.  
  60.  
  61. /** 
  62. * parse an XML file 
  63. * @param string $xml path/URL to XML file 
  64. * @param string $type (schema | xml) 
  65. * @return boolean 
  66. * @access public 
  67. */ 
  68. function parseFile($xml, $type) { 
  69. // parse xml file 
  70. if($xml != "") { 
  71. $xmlStr = @join("", @file($xml)); 
  72. if($xmlStr == "") { 
  73. $msg = 'Error reading XML from '.$xml; 
  74. $this->setError($msg); 
  75. $this->debug($msg); 
  76. return false; 
  77. } else { 
  78. $this->debug("parsing $xml"); 
  79. $this->parseString($xmlStr, $type); 
  80. $this->debug("done parsing $xml"); 
  81. return true; 
  82. return false; 
  83.  
  84. /** 
  85. * parse an XML string 
  86. * @param string $xml path or URL 
  87. * @param string $type (schema|xml) 
  88. * @access private 
  89. */ 
  90. function parseString($xml, $type) { 
  91. // parse xml string 
  92. if($xml != "") { 
  93.  
  94. // Create an XML parser. 
  95. $this->parser = xml_parser_create(); 
  96. // Set the options for parsing the XML data. 
  97. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); 
  98.  
  99. // Set the object for the parser. 
  100. xml_set_object($this->parser, $this); 
  101.  
  102. // Set the element handlers for the parser. 
  103. if($type == "schema") { 
  104. xml_set_element_handler($this->parser, 'schemaStartElement', 'schemaEndElement'); 
  105. xml_set_character_data_handler($this->parser, 'schemaCharacterData'); 
  106. } elseif($type == "xml") { 
  107. xml_set_element_handler($this->parser, 'xmlStartElement', 'xmlEndElement'); 
  108. xml_set_character_data_handler($this->parser, 'xmlCharacterData'); 
  109.  
  110. // Parse the XML file. 
  111. if(!xml_parse($this->parser, $xml, true)) { 
  112. // Display an error message. 
  113. $errstr = sprintf('XML error parsing XML schema on line %d: %s',  
  114. xml_get_current_line_number($this->parser),  
  115. xml_error_string(xml_get_error_code($this->parser)) 
  116. ); 
  117. $this->debug($errstr); 
  118. $this->debug("XML payload:\n" . $xml); 
  119. $this->setError($errstr); 
  120.  
  121. xml_parser_free($this->parser); 
  122. } else{ 
  123. $this->debug('no xml passed to parseString()!!'); 
  124. $this->setError('no xml passed to parseString()!!'); 
  125.  
  126. /** 
  127. * gets a type name for an unnamed type 
  128. * @param string Element name 
  129. * @return string A type name for an unnamed type 
  130. * @access private 
  131. */ 
  132. function CreateTypeName($ename) { 
  133. $scope = ''; 
  134. for ($i = 0; $i < count($this->complexTypeStack); $i++) { 
  135. $scope .= $this->complexTypeStack[$i] . '_'; 
  136. return $scope . $ename . '_ContainedType'; 
  137.  
  138. /** 
  139. * start-element handler 
  140. * @param string $parser XML parser object 
  141. * @param string $name element name 
  142. * @param string $attrs associative array of attributes 
  143. * @access private 
  144. */ 
  145. function schemaStartElement($parser, $name, $attrs) { 
  146.  
  147. // position in the total number of elements, starting from 0 
  148. $pos = $this->position++; 
  149. $depth = $this->depth++; 
  150. // set self as current value for this depth 
  151. $this->depth_array[$depth] = $pos; 
  152. $this->message[$pos] = array('cdata' => '');  
  153. if ($depth > 0) { 
  154. $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]]; 
  155. } else { 
  156. $this->defaultNamespace[$pos] = false; 
  157.  
  158. // get element prefix 
  159. if($prefix = $this->getPrefix($name)) { 
  160. // get unqualified name 
  161. $name = $this->getLocalPart($name); 
  162. } else { 
  163. $prefix = ''; 
  164.  
  165. // loop thru attributes, expanding, and registering namespace declarations 
  166. if(count($attrs) > 0) { 
  167. foreach($attrs as $k => $v) { 
  168. // if ns declarations, add to class level array of valid namespaces 
  169. if(preg_match('/^xmlns/', $k)) { 
  170. //$this->xdebug("$k: $v"); 
  171. //$this->xdebug('ns_prefix: '.$this->getPrefix($k)); 
  172. if($ns_prefix = substr(strrchr($k, ':'), 1)) { 
  173. //$this->xdebug("Add namespace[$ns_prefix] = $v"); 
  174. $this->namespaces[$ns_prefix] = $v; 
  175. } else { 
  176. $this->defaultNamespace[$pos] = $v; 
  177. if (! $this->getPrefixFromNamespace($v)) { 
  178. $this->namespaces['ns'.(count($this->namespaces)+1)] = $v; 
  179. if($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') { 
  180. $this->XMLSchemaVersion = $v; 
  181. $this->namespaces['xsi'] = $v.'-instance'; 
  182. foreach($attrs as $k => $v) { 
  183. // expand each attribute 
  184. $k = strpos($k, ':') ? $this->expandQname($k) : $k; 
  185. $v = strpos($v, ':') ? $this->expandQname($v) : $v; 
  186. $eAttrs[$k] = $v; 
  187. $attrs = $eAttrs; 
  188. } else { 
  189. $attrs = array(); 
  190. // find status, register data 
  191. switch($name) { 
  192. case 'all': // (optional) compositor content for a complexType 
  193. case 'choice': 
  194. case 'group': 
  195. case 'sequence': 
  196. //$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement"); 
  197. $this->complexTypes[$this->currentComplexType]['compositor'] = $name; 
  198. //if($name == 'all' || $name == 'sequence') { 
  199. // $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; 
  200. //} 
  201. break; 
  202. case 'attribute': // complexType attribute 
  203. //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']); 
  204. $this->xdebug("parsing attribute:"); 
  205. $this->appendDebug($this->varDump($attrs)); 
  206. if (!isset($attrs['form'])) { 
  207. // TODO: handle globals 
  208. $attrs['form'] = $this->schemaInfo['attributeFormDefault']; 
  209. if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { 
  210. $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; 
  211. if (!strpos($v, ':')) { 
  212. // no namespace in arrayType attribute value... 
  213. if ($this->defaultNamespace[$pos]) { 
  214. // ...so use the default 
  215. $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; 
  216. if(isset($attrs['name'])) { 
  217. $this->attributes[$attrs['name']] = $attrs; 
  218. $aname = $attrs['name']; 
  219. } elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType') { 
  220. if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { 
  221. $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; 
  222. } else { 
  223. $aname = ''; 
  224. } elseif(isset($attrs['ref'])) { 
  225. $aname = $attrs['ref']; 
  226. $this->attributes[$attrs['ref']] = $attrs; 
  227.  
  228. if($this->currentComplexType) { // This should *always* be 
  229. $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs; 
  230. // arrayType attribute 
  231. if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType') { 
  232. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; 
  233. $prefix = $this->getPrefix($aname); 
  234. if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { 
  235. $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; 
  236. } else { 
  237. $v = ''; 
  238. if(strpos($v, '[, ]')) { 
  239. $this->complexTypes[$this->currentComplexType]['multidimensional'] = true; 
  240. $v = substr($v, 0, strpos($v, '[')); // clip the [] 
  241. if(!strpos($v, ':') && isset($this->typemap[$this->XMLSchemaVersion][$v])) { 
  242. $v = $this->XMLSchemaVersion.':'.$v; 
  243. $this->complexTypes[$this->currentComplexType]['arrayType'] = $v; 
  244. break; 
  245. case 'complexContent': // (optional) content for a complexType 
  246. $this->xdebug("do nothing for element $name"); 
  247. break; 
  248. case 'complexType': 
  249. array_push($this->complexTypeStack, $this->currentComplexType); 
  250. if(isset($attrs['name'])) { 
  251. // TODO: what is the scope of named complexTypes that appear 
  252. // nested within other c complexTypes? 
  253. $this->xdebug('processing named complexType '.$attrs['name']); 
  254. //$this->currentElement = false; 
  255. $this->currentComplexType = $attrs['name']; 
  256. $this->complexTypes[$this->currentComplexType] = $attrs; 
  257. $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType'; 
  258. // This is for constructs like 
  259. // <complexType name="ListOfString" base="soap:Array"> 
  260. // <sequence> 
  261. // <element name="string" type="xsd:string" 
  262. // minOccurs="0" maxOccurs="unbounded" /> 
  263. // </sequence> 
  264. // </complexType> 
  265. if(isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) { 
  266. $this->xdebug('complexType is unusual array'); 
  267. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; 
  268. } else { 
  269. $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; 
  270. } else { 
  271. $name = $this->CreateTypeName($this->currentElement); 
  272. $this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name); 
  273. $this->currentComplexType = $name; 
  274. //$this->currentElement = false; 
  275. $this->complexTypes[$this->currentComplexType] = $attrs; 
  276. $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType'; 
  277. // This is for constructs like 
  278. // <complexType name="ListOfString" base="soap:Array"> 
  279. // <sequence> 
  280. // <element name="string" type="xsd:string" 
  281. // minOccurs="0" maxOccurs="unbounded" /> 
  282. // </sequence> 
  283. // </complexType> 
  284. if(isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) { 
  285. $this->xdebug('complexType is unusual array'); 
  286. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; 
  287. } else { 
  288. $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; 
  289. $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false'; 
  290. break; 
  291. case 'element': 
  292. array_push($this->elementStack, $this->currentElement); 
  293. if (!isset($attrs['form'])) { 
  294. if ($this->currentComplexType) { 
  295. $attrs['form'] = $this->schemaInfo['elementFormDefault']; 
  296. } else { 
  297. // global 
  298. $attrs['form'] = 'qualified'; 
  299. if(isset($attrs['type'])) { 
  300. $this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']); 
  301. if (! $this->getPrefix($attrs['type'])) { 
  302. if ($this->defaultNamespace[$pos]) { 
  303. $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type']; 
  304. $this->xdebug('used default namespace to make type ' . $attrs['type']); 
  305. // This is for constructs like 
  306. // <complexType name="ListOfString" base="soap:Array"> 
  307. // <sequence> 
  308. // <element name="string" type="xsd:string" 
  309. // minOccurs="0" maxOccurs="unbounded" /> 
  310. // </sequence> 
  311. // </complexType> 
  312. if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') { 
  313. $this->xdebug('arrayType for unusual array is ' . $attrs['type']); 
  314. $this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type']; 
  315. $this->currentElement = $attrs['name']; 
  316. $ename = $attrs['name']; 
  317. } elseif(isset($attrs['ref'])) { 
  318. $this->xdebug("processing element as ref to ".$attrs['ref']); 
  319. $this->currentElement = "ref to ".$attrs['ref']; 
  320. $ename = $this->getLocalPart($attrs['ref']); 
  321. } else { 
  322. $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']); 
  323. $this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type); 
  324. $this->currentElement = $attrs['name']; 
  325. $attrs['type'] = $this->schemaTargetNamespace . ':' . $type; 
  326. $ename = $attrs['name']; 
  327. if (isset($ename) && $this->currentComplexType) { 
  328. $this->xdebug("add element $ename to complexType $this->currentComplexType"); 
  329. $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs; 
  330. } elseif (!isset($attrs['ref'])) { 
  331. $this->xdebug("add element $ename to elements array"); 
  332. $this->elements[ $attrs['name'] ] = $attrs; 
  333. $this->elements[ $attrs['name'] ]['typeClass'] = 'element'; 
  334. break; 
  335. case 'enumeration': // restriction value list member 
  336. $this->xdebug('enumeration ' . $attrs['value']); 
  337. if ($this->currentSimpleType) { 
  338. $this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value']; 
  339. } elseif ($this->currentComplexType) { 
  340. $this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value']; 
  341. break; 
  342. case 'extension': // simpleContent or complexContent type extension 
  343. $this->xdebug('extension ' . $attrs['base']); 
  344. if ($this->currentComplexType) { 
  345. $ns = $this->getPrefix($attrs['base']); 
  346. if ($ns == '') { 
  347. $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base']; 
  348. } else { 
  349. $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base']; 
  350. } else { 
  351. $this->xdebug('no current complexType to set extensionBase'); 
  352. break; 
  353. case 'import': 
  354. if (isset($attrs['schemaLocation'])) { 
  355. $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']); 
  356. $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false); 
  357. } else { 
  358. $this->xdebug('import namespace ' . $attrs['namespace']); 
  359. $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true); 
  360. if (! $this->getPrefixFromNamespace($attrs['namespace'])) { 
  361. $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace']; 
  362. break; 
  363. case 'include': 
  364. if (isset($attrs['schemaLocation'])) { 
  365. $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']); 
  366. $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false); 
  367. } else { 
  368. $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute'); 
  369. break; 
  370. case 'list': // simpleType value list 
  371. $this->xdebug("do nothing for element $name"); 
  372. break; 
  373. case 'restriction': // simpleType, simpleContent or complexContent value restriction 
  374. $this->xdebug('restriction ' . $attrs['base']); 
  375. if($this->currentSimpleType) { 
  376. $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base']; 
  377. } elseif($this->currentComplexType) { 
  378. $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base']; 
  379. if(strstr($attrs['base'], ':') == ':Array') { 
  380. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; 
  381. break; 
  382. case 'schema': 
  383. $this->schemaInfo = $attrs; 
  384. $this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix); 
  385. if (isset($attrs['targetNamespace'])) { 
  386. $this->schemaTargetNamespace = $attrs['targetNamespace']; 
  387. if (!isset($attrs['elementFormDefault'])) { 
  388. $this->schemaInfo['elementFormDefault'] = 'unqualified'; 
  389. if (!isset($attrs['attributeFormDefault'])) { 
  390. $this->schemaInfo['attributeFormDefault'] = 'unqualified'; 
  391. break; 
  392. case 'simpleContent': // (optional) content for a complexType 
  393. if ($this->currentComplexType) { // This should *always* be 
  394. $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true'; 
  395. } else { 
  396. $this->xdebug("do nothing for element $name because there is no current complexType"); 
  397. break; 
  398. case 'simpleType': 
  399. array_push($this->simpleTypeStack, $this->currentSimpleType); 
  400. if(isset($attrs['name'])) { 
  401. $this->xdebug("processing simpleType for name " . $attrs['name']); 
  402. $this->currentSimpleType = $attrs['name']; 
  403. $this->simpleTypes[ $attrs['name'] ] = $attrs; 
  404. $this->simpleTypes[ $attrs['name'] ]['typeClass'] = 'simpleType'; 
  405. $this->simpleTypes[ $attrs['name'] ]['phpType'] = 'scalar'; 
  406. } else { 
  407. $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement); 
  408. $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name); 
  409. $this->currentSimpleType = $name; 
  410. //$this->currentElement = false; 
  411. $this->simpleTypes[$this->currentSimpleType] = $attrs; 
  412. $this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar'; 
  413. break; 
  414. case 'union': // simpleType type list 
  415. $this->xdebug("do nothing for element $name"); 
  416. break; 
  417. default: 
  418. $this->xdebug("do not have any logic to process element $name"); 
  419.  
  420. /** 
  421. * end-element handler 
  422. * @param string $parser XML parser object 
  423. * @param string $name element name 
  424. * @access private 
  425. */ 
  426. function schemaEndElement($parser, $name) { 
  427. // bring depth down a notch 
  428. $this->depth--; 
  429. // position of current element is equal to the last value left in depth_array for my depth 
  430. if(isset($this->depth_array[$this->depth])) { 
  431. $pos = $this->depth_array[$this->depth]; 
  432. // get element prefix 
  433. if ($prefix = $this->getPrefix($name)) { 
  434. // get unqualified name 
  435. $name = $this->getLocalPart($name); 
  436. } else { 
  437. $prefix = ''; 
  438. // move on... 
  439. if($name == 'complexType') { 
  440. $this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)')); 
  441. $this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType])); 
  442. $this->currentComplexType = array_pop($this->complexTypeStack); 
  443. //$this->currentElement = false; 
  444. if($name == 'element') { 
  445. $this->xdebug('done processing element ' . ($this->currentElement ? $this->currentElement : '(unknown)')); 
  446. $this->currentElement = array_pop($this->elementStack); 
  447. if($name == 'simpleType') { 
  448. $this->xdebug('done processing simpleType ' . ($this->currentSimpleType ? $this->currentSimpleType : '(unknown)')); 
  449. $this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType])); 
  450. $this->currentSimpleType = array_pop($this->simpleTypeStack); 
  451.  
  452. /** 
  453. * element content handler 
  454. * @param string $parser XML parser object 
  455. * @param string $data element content 
  456. * @access private 
  457. */ 
  458. function schemaCharacterData($parser, $data) { 
  459. $pos = $this->depth_array[$this->depth - 1]; 
  460. $this->message[$pos]['cdata'] .= $data; 
  461.  
  462. /** 
  463. * serialize the schema 
  464. * @access public 
  465. */ 
  466. function serializeSchema() { 
  467.  
  468. $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion); 
  469. $xml = ''; 
  470. // imports 
  471. if (sizeof($this->imports) > 0) { 
  472. foreach($this->imports as $ns => $list) { 
  473. foreach ($list as $ii) { 
  474. if ($ii['location'] != '') { 
  475. $xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n"; 
  476. } else { 
  477. $xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n"; 
  478. }  
  479. }  
  480. // complex types 
  481. foreach($this->complexTypes as $typeName => $attrs) { 
  482. $contentStr = ''; 
  483. // serialize child elements 
  484. if(isset($attrs['elements']) && (count($attrs['elements']) > 0)) { 
  485. foreach($attrs['elements'] as $element => $eParts) { 
  486. if(isset($eParts['ref'])) { 
  487. $contentStr .= " <$schemaPrefix:element ref=\"$element\"/>\n"; 
  488. } else { 
  489. $contentStr .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\""; 
  490. foreach ($eParts as $aName => $aValue) { 
  491. // handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable 
  492. if ($aName != 'name' && $aName != 'type') { 
  493. $contentStr .= " $aName=\"$aValue\""; 
  494. $contentStr .= "/>\n"; 
  495. // compositor wraps elements 
  496. if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) { 
  497. $contentStr = " <$schemaPrefix:$attrs[compositor]>\n".$contentStr." </$schemaPrefix:$attrs[compositor]>\n"; 
  498. // attributes 
  499. if(isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)) { 
  500. foreach($attrs['attrs'] as $attr => $aParts) { 
  501. $contentStr .= " <$schemaPrefix:attribute"; 
  502. foreach ($aParts as $a => $v) { 
  503. if ($a == 'ref' || $a == 'type') { 
  504. $contentStr .= " $a=\"".$this->contractQName($v).'"'; 
  505. } elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') { 
  506. $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl']; 
  507. $contentStr .= ' wsdl:arrayType="'.$this->contractQName($v).'"'; 
  508. } else { 
  509. $contentStr .= " $a=\"$v\""; 
  510. $contentStr .= "/>\n"; 
  511. // if restriction 
  512. if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != '') { 
  513. $contentStr = " <$schemaPrefix:restriction base=\"".$this->contractQName($attrs['restrictionBase'])."\">\n".$contentStr." </$schemaPrefix:restriction>\n"; 
  514. // complex or simple content 
  515. if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)) { 
  516. $contentStr = " <$schemaPrefix:complexContent>\n".$contentStr." </$schemaPrefix:complexContent>\n"; 
  517. // finalize complex type 
  518. if($contentStr != '') { 
  519. $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n".$contentStr." </$schemaPrefix:complexType>\n"; 
  520. } else { 
  521. $contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n"; 
  522. $xml .= $contentStr; 
  523. // simple types 
  524. if(isset($this->simpleTypes) && count($this->simpleTypes) > 0) { 
  525. foreach($this->simpleTypes as $typeName => $eParts) { 
  526. $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n <$schemaPrefix:restriction base=\"".$this->contractQName($eParts['type'])."\">\n"; 
  527. if (isset($eParts['enumeration'])) { 
  528. foreach ($eParts['enumeration'] as $e) { 
  529. $xml .= " <$schemaPrefix:enumeration value=\"$e\"/>\n"; 
  530. $xml .= " </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>"; 
  531. // elements 
  532. if(isset($this->elements) && count($this->elements) > 0) { 
  533. foreach($this->elements as $element => $eParts) { 
  534. $xml .= " <$schemaPrefix:element name=\"$element\" type=\"".$this->contractQName($eParts['type'])."\"/>\n"; 
  535. // attributes 
  536. if(isset($this->attributes) && count($this->attributes) > 0) { 
  537. foreach($this->attributes as $attr => $aParts) { 
  538. $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"".$this->contractQName($aParts['type'])."\"\n/>"; 
  539. // finish 'er up 
  540. $attr = ''; 
  541. foreach ($this->schemaInfo as $k => $v) { 
  542. if ($k == 'elementFormDefault' || $k == 'attributeFormDefault') { 
  543. $attr .= " $k=\"$v\""; 
  544. $el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n"; 
  545. foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) { 
  546. $el .= " xmlns:$nsp=\"$ns\""; 
  547. $xml = $el . ">\n".$xml."</$schemaPrefix:schema>\n"; 
  548. return $xml; 
  549.  
  550. /** 
  551. * adds debug data to the clas level debug string 
  552. * @param string $string debug data 
  553. * @access private 
  554. */ 
  555. function xdebug($string) { 
  556. $this->debug('<' . $this->schemaTargetNamespace . '> '.$string); 
  557.  
  558. /** 
  559. * get the PHP type of a user defined type in the schema 
  560. * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays 
  561. * returns false if no type exists, or not w/ the given namespace 
  562. * else returns a string that is either a native php type, or 'struct' 
  563. * @param string $type name of defined type 
  564. * @param string $ns namespace of type 
  565. * @return mixed 
  566. * @access public 
  567. * @deprecated 
  568. */ 
  569. function getPHPType($type, $ns) { 
  570. if(isset($this->typemap[$ns][$type])) { 
  571. //print "found type '$type' and ns $ns in typemap<br>"; 
  572. return $this->typemap[$ns][$type]; 
  573. } elseif(isset($this->complexTypes[$type])) { 
  574. //print "getting type '$type' and ns $ns from complexTypes array<br>"; 
  575. return $this->complexTypes[$type]['phpType']; 
  576. return false; 
  577.  
  578. /** 
  579. * returns an associative array of information about a given type 
  580. * returns false if no type exists by the given name 
  581. * For a complexType typeDef = array( 
  582. * 'restrictionBase' => '',  
  583. * 'phpType' => '',  
  584. * 'compositor' => '(sequence|all)',  
  585. * 'elements' => array(), // refs to elements array 
  586. * 'attrs' => array() // refs to attributes array 
  587. * ... and so on (see addComplexType) 
  588. * ) 
  589. * For simpleType or element, the array has different keys. 
  590. * @param string $type 
  591. * @return mixed 
  592. * @access public 
  593. * @see addComplexType 
  594. * @see addSimpleType 
  595. * @see addElement 
  596. */ 
  597. function getTypeDef($type) { 
  598. //$this->debug("in getTypeDef for type $type"); 
  599. if (substr($type, -1) == '^') { 
  600. $is_element = 1; 
  601. $type = substr($type, 0, -1); 
  602. } else { 
  603. $is_element = 0; 
  604.  
  605. if((! $is_element) && isset($this->complexTypes[$type])) { 
  606. $this->xdebug("in getTypeDef, found complexType $type"); 
  607. return $this->complexTypes[$type]; 
  608. } elseif((! $is_element) && isset($this->simpleTypes[$type])) { 
  609. $this->xdebug("in getTypeDef, found simpleType $type"); 
  610. if (!isset($this->simpleTypes[$type]['phpType'])) { 
  611. // get info for type to tack onto the simple type 
  612. // TODO: can this ever really apply (i.e. what is a simpleType really?) 
  613. $uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1); 
  614. $ns = substr($this->simpleTypes[$type]['type'], 0, strrpos($this->simpleTypes[$type]['type'], ':')); 
  615. $etype = $this->getTypeDef($uqType); 
  616. if ($etype) { 
  617. $this->xdebug("in getTypeDef, found type for simpleType $type:"); 
  618. $this->xdebug($this->varDump($etype)); 
  619. if (isset($etype['phpType'])) { 
  620. $this->simpleTypes[$type]['phpType'] = $etype['phpType']; 
  621. if (isset($etype['elements'])) { 
  622. $this->simpleTypes[$type]['elements'] = $etype['elements']; 
  623. return $this->simpleTypes[$type]; 
  624. } elseif(isset($this->elements[$type])) { 
  625. $this->xdebug("in getTypeDef, found element $type"); 
  626. if (!isset($this->elements[$type]['phpType'])) { 
  627. // get info for type to tack onto the element 
  628. $uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1); 
  629. $ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':')); 
  630. $etype = $this->getTypeDef($uqType); 
  631. if ($etype) { 
  632. $this->xdebug("in getTypeDef, found type for element $type:"); 
  633. $this->xdebug($this->varDump($etype)); 
  634. if (isset($etype['phpType'])) { 
  635. $this->elements[$type]['phpType'] = $etype['phpType']; 
  636. if (isset($etype['elements'])) { 
  637. $this->elements[$type]['elements'] = $etype['elements']; 
  638. if (isset($etype['extensionBase'])) { 
  639. $this->elements[$type]['extensionBase'] = $etype['extensionBase']; 
  640. } elseif ($ns == 'http://www.w3.org/2001/XMLSchema') { 
  641. $this->xdebug("in getTypeDef, element $type is an XSD type"); 
  642. $this->elements[$type]['phpType'] = 'scalar'; 
  643. return $this->elements[$type]; 
  644. } elseif(isset($this->attributes[$type])) { 
  645. $this->xdebug("in getTypeDef, found attribute $type"); 
  646. return $this->attributes[$type]; 
  647. } elseif (preg_match('/_ContainedType$/', $type)) { 
  648. $this->xdebug("in getTypeDef, have an untyped element $type"); 
  649. $typeDef['typeClass'] = 'simpleType'; 
  650. $typeDef['phpType'] = 'scalar'; 
  651. $typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string'; 
  652. return $typeDef; 
  653. $this->xdebug("in getTypeDef, did not find $type"); 
  654. return false; 
  655.  
  656. /** 
  657. * returns a sample serialization of a given type, or false if no type by the given name 
  658. * @param string $type name of type 
  659. * @return mixed 
  660. * @access public 
  661. * @deprecated 
  662. */ 
  663. function serializeTypeDef($type) { 
  664. //print "in sTD() for type $type<br>"; 
  665. if($typeDef = $this->getTypeDef($type)) { 
  666. $str .= '<'.$type; 
  667. if(is_array($typeDef['attrs'])) { 
  668. foreach($typeDef['attrs'] as $attName => $data) { 
  669. $str .= " $attName=\"{type = ".$data['type']."}\""; 
  670. $str .= " xmlns=\"".$this->schema['targetNamespace']."\""; 
  671. if(count($typeDef['elements']) > 0) { 
  672. $str .= ">"; 
  673. foreach($typeDef['elements'] as $element => $eData) { 
  674. $str .= $this->serializeTypeDef($element); 
  675. $str .= "</$type>"; 
  676. } elseif($typeDef['typeClass'] == 'element') { 
  677. $str .= "></$type>"; 
  678. } else { 
  679. $str .= "/>"; 
  680. return $str; 
  681. return false; 
  682.  
  683. /** 
  684. * returns HTML form elements that allow a user 
  685. * to enter values for creating an instance of the given type. 
  686. * @param string $name name for type instance 
  687. * @param string $type name of type 
  688. * @return string 
  689. * @access public 
  690. * @deprecated 
  691. */ 
  692. function typeToForm($name, $type) { 
  693. // get typedef 
  694. if($typeDef = $this->getTypeDef($type)) { 
  695. // if struct 
  696. if($typeDef['phpType'] == 'struct') { 
  697. $buffer .= '<table>'; 
  698. foreach($typeDef['elements'] as $child => $childDef) { 
  699. $buffer .= " 
  700. <tr><td align='right'>$childDef[name] (type: ".$this->getLocalPart($childDef['type'])."):</td> 
  701. <td><input type='text' name='parameters[".$name."][$childDef[name]]'></td></tr>"; 
  702. $buffer .= '</table>'; 
  703. // if array 
  704. } elseif($typeDef['phpType'] == 'array') { 
  705. $buffer .= '<table>'; 
  706. for($i=0;$i < 3; $i++) { 
  707. $buffer .= " 
  708. <tr><td align='right'>array item (type: $typeDef[arrayType]):</td> 
  709. <td><input type='text' name='parameters[".$name."][]'></td></tr>"; 
  710. $buffer .= '</table>'; 
  711. // if scalar 
  712. } else { 
  713. $buffer .= "<input type='text' name='parameters[$name]'>"; 
  714. } else { 
  715. $buffer .= "<input type='text' name='parameters[$name]'>"; 
  716. return $buffer; 
  717.  
  718. /** 
  719. * adds a complex type to the schema 
  720. *  
  721. * example: array 
  722. *  
  723. * addType( 
  724. * 'ArrayOfstring',  
  725. * 'complexType',  
  726. * 'array',  
  727. * '',  
  728. * 'SOAP-ENC:Array',  
  729. * array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType'=>'string[]'),  
  730. * 'xsd:string' 
  731. * ); 
  732. *  
  733. * example: PHP associative array ( SOAP Struct ) 
  734. *  
  735. * addType( 
  736. * 'SOAPStruct',  
  737. * 'complexType',  
  738. * 'struct',  
  739. * 'all',  
  740. * array('myVar'=> array('name'=>'myVar', 'type'=>'string') 
  741. * ); 
  742. *  
  743. * @param name 
  744. * @param typeClass (complexType|simpleType|attribute) 
  745. * @param phpType: currently supported are array and struct (php assoc array) 
  746. * @param compositor (all|sequence|choice) 
  747. * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) 
  748. * @param elements = array ( name = array(name=>'', type=>'') ) 
  749. * @param attrs = array( 
  750. * array( 
  751. * 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",  
  752. * "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]" 
  753. * ) 
  754. * ) 
  755. * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string) 
  756. * @access public 
  757. * @see getTypeDef 
  758. */ 
  759. function addComplexType($name, $typeClass='complexType', $phpType='array', $compositor='', $restrictionBase='', $elements=array(), $attrs=array(), $arrayType='') { 
  760. $this->complexTypes[$name] = array( 
  761. 'name' => $name,  
  762. 'typeClass' => $typeClass,  
  763. 'phpType' => $phpType,  
  764. 'compositor'=> $compositor,  
  765. 'restrictionBase' => $restrictionBase,  
  766. 'elements' => $elements,  
  767. 'attrs' => $attrs,  
  768. 'arrayType' => $arrayType 
  769. ); 
  770.  
  771. $this->xdebug("addComplexType $name:"); 
  772. $this->appendDebug($this->varDump($this->complexTypes[$name])); 
  773.  
  774. /** 
  775. * adds a simple type to the schema 
  776. * @param string $name 
  777. * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) 
  778. * @param string $typeClass (should always be simpleType) 
  779. * @param string $phpType (should always be scalar) 
  780. * @param array $enumeration array of values 
  781. * @access public 
  782. * @see nusoap_xmlschema 
  783. * @see getTypeDef 
  784. */ 
  785. function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) { 
  786. $this->simpleTypes[$name] = array( 
  787. 'name' => $name,  
  788. 'typeClass' => $typeClass,  
  789. 'phpType' => $phpType,  
  790. 'type' => $restrictionBase,  
  791. 'enumeration' => $enumeration 
  792. ); 
  793.  
  794. $this->xdebug("addSimpleType $name:"); 
  795. $this->appendDebug($this->varDump($this->simpleTypes[$name])); 
  796.  
  797. /** 
  798. * adds an element to the schema 
  799. * @param array $attrs attributes that must include name and type 
  800. * @see nusoap_xmlschema 
  801. * @access public 
  802. */ 
  803. function addElement($attrs) { 
  804. if (! $this->getPrefix($attrs['type'])) { 
  805. $attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type']; 
  806. $this->elements[ $attrs['name'] ] = $attrs; 
  807. $this->elements[ $attrs['name'] ]['typeClass'] = 'element'; 
  808.  
  809. $this->xdebug("addElement " . $attrs['name']); 
  810. $this->appendDebug($this->varDump($this->elements[ $attrs['name'] ])); 
/lib/nusoap.php  
  1. class nusoap_xmlschema extends nusoap_base { 
  2.  
  3. // files 
  4. var $schema = ''; 
  5. var $xml = ''; 
  6. // namespaces 
  7. var $enclosingNamespaces; 
  8. // schema info 
  9. var $schemaInfo = array(); 
  10. var $schemaTargetNamespace = ''; 
  11. // types, elements, attributes defined by the schema 
  12. var $attributes = array(); 
  13. var $complexTypes = array(); 
  14. var $complexTypeStack = array(); 
  15. var $currentComplexType = null; 
  16. var $elements = array(); 
  17. var $elementStack = array(); 
  18. var $currentElement = null; 
  19. var $simpleTypes = array(); 
  20. var $simpleTypeStack = array(); 
  21. var $currentSimpleType = null; 
  22. // imports 
  23. var $imports = array(); 
  24. // parser vars 
  25. var $parser; 
  26. var $position = 0; 
  27. var $depth = 0; 
  28. var $depth_array = array(); 
  29. var $message = array(); 
  30. var $defaultNamespace = array(); 
  31.  
  32. /** 
  33. * constructor 
  34. * @param string $schema schema document URI 
  35. * @param string $xml xml document URI 
  36. * @param string $namespaces namespaces defined in enclosing XML 
  37. * @access public 
  38. */ 
  39. function nusoap_xmlschema($schema='', $xml='', $namespaces=array()) { 
  40. parent::nusoap_base(); 
  41. $this->debug('nusoap_xmlschema class instantiated, inside constructor'); 
  42. // files 
  43. $this->schema = $schema; 
  44. $this->xml = $xml; 
  45.  
  46. // namespaces 
  47. $this->enclosingNamespaces = $namespaces; 
  48. $this->namespaces = array_merge($this->namespaces, $namespaces); 
  49.  
  50. // parse schema file 
  51. if($schema != '') { 
  52. $this->debug('initial schema file: '.$schema); 
  53. $this->parseFile($schema, 'schema'); 
  54.  
  55. // parse xml file 
  56. if($xml != '') { 
  57. $this->debug('initial xml file: '.$xml); 
  58. $this->parseFile($xml, 'xml'); 
  59.  
  60.  
  61. /** 
  62. * parse an XML file 
  63. * @param string $xml path/URL to XML file 
  64. * @param string $type (schema | xml) 
  65. * @return boolean 
  66. * @access public 
  67. */ 
  68. function parseFile($xml, $type) { 
  69. // parse xml file 
  70. if($xml != "") { 
  71. $xmlStr = @join("", @file($xml)); 
  72. if($xmlStr == "") { 
  73. $msg = 'Error reading XML from '.$xml; 
  74. $this->setError($msg); 
  75. $this->debug($msg); 
  76. return false; 
  77. } else { 
  78. $this->debug("parsing $xml"); 
  79. $this->parseString($xmlStr, $type); 
  80. $this->debug("done parsing $xml"); 
  81. return true; 
  82. return false; 
  83.  
  84. /** 
  85. * parse an XML string 
  86. * @param string $xml path or URL 
  87. * @param string $type (schema|xml) 
  88. * @access private 
  89. */ 
  90. function parseString($xml, $type) { 
  91. // parse xml string 
  92. if($xml != "") { 
  93.  
  94. // Create an XML parser. 
  95. $this->parser = xml_parser_create(); 
  96. // Set the options for parsing the XML data. 
  97. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); 
  98.  
  99. // Set the object for the parser. 
  100. xml_set_object($this->parser, $this); 
  101.  
  102. // Set the element handlers for the parser. 
  103. if($type == "schema") { 
  104. xml_set_element_handler($this->parser, 'schemaStartElement', 'schemaEndElement'); 
  105. xml_set_character_data_handler($this->parser, 'schemaCharacterData'); 
  106. } elseif($type == "xml") { 
  107. xml_set_element_handler($this->parser, 'xmlStartElement', 'xmlEndElement'); 
  108. xml_set_character_data_handler($this->parser, 'xmlCharacterData'); 
  109.  
  110. // Parse the XML file. 
  111. if(!xml_parse($this->parser, $xml, true)) { 
  112. // Display an error message. 
  113. $errstr = sprintf('XML error parsing XML schema on line %d: %s',  
  114. xml_get_current_line_number($this->parser),  
  115. xml_error_string(xml_get_error_code($this->parser)) 
  116. ); 
  117. $this->debug($errstr); 
  118. $this->debug("XML payload:\n" . $xml); 
  119. $this->setError($errstr); 
  120.  
  121. xml_parser_free($this->parser); 
  122. } else{ 
  123. $this->debug('no xml passed to parseString()!!'); 
  124. $this->setError('no xml passed to parseString()!!'); 
  125.  
  126. /** 
  127. * gets a type name for an unnamed type 
  128. * @param string Element name 
  129. * @return string A type name for an unnamed type 
  130. * @access private 
  131. */ 
  132. function CreateTypeName($ename) { 
  133. $scope = ''; 
  134. for ($i = 0; $i < count($this->complexTypeStack); $i++) { 
  135. $scope .= $this->complexTypeStack[$i] . '_'; 
  136. return $scope . $ename . '_ContainedType'; 
  137.  
  138. /** 
  139. * start-element handler 
  140. * @param string $parser XML parser object 
  141. * @param string $name element name 
  142. * @param string $attrs associative array of attributes 
  143. * @access private 
  144. */ 
  145. function schemaStartElement($parser, $name, $attrs) { 
  146.  
  147. // position in the total number of elements, starting from 0 
  148. $pos = $this->position++; 
  149. $depth = $this->depth++; 
  150. // set self as current value for this depth 
  151. $this->depth_array[$depth] = $pos; 
  152. $this->message[$pos] = array('cdata' => '');  
  153. if ($depth > 0) { 
  154. $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]]; 
  155. } else { 
  156. $this->defaultNamespace[$pos] = false; 
  157.  
  158. // get element prefix 
  159. if($prefix = $this->getPrefix($name)) { 
  160. // get unqualified name 
  161. $name = $this->getLocalPart($name); 
  162. } else { 
  163. $prefix = ''; 
  164.  
  165. // loop thru attributes, expanding, and registering namespace declarations 
  166. if(count($attrs) > 0) { 
  167. foreach($attrs as $k => $v) { 
  168. // if ns declarations, add to class level array of valid namespaces 
  169. if(preg_match('/^xmlns/', $k)) { 
  170. //$this->xdebug("$k: $v"); 
  171. //$this->xdebug('ns_prefix: '.$this->getPrefix($k)); 
  172. if($ns_prefix = substr(strrchr($k, ':'), 1)) { 
  173. //$this->xdebug("Add namespace[$ns_prefix] = $v"); 
  174. $this->namespaces[$ns_prefix] = $v; 
  175. } else { 
  176. $this->defaultNamespace[$pos] = $v; 
  177. if (! $this->getPrefixFromNamespace($v)) { 
  178. $this->namespaces['ns'.(count($this->namespaces)+1)] = $v; 
  179. if($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') { 
  180. $this->XMLSchemaVersion = $v; 
  181. $this->namespaces['xsi'] = $v.'-instance'; 
  182. foreach($attrs as $k => $v) { 
  183. // expand each attribute 
  184. $k = strpos($k, ':') ? $this->expandQname($k) : $k; 
  185. $v = strpos($v, ':') ? $this->expandQname($v) : $v; 
  186. $eAttrs[$k] = $v; 
  187. $attrs = $eAttrs; 
  188. } else { 
  189. $attrs = array(); 
  190. // find status, register data 
  191. switch($name) { 
  192. case 'all': // (optional) compositor content for a complexType 
  193. case 'choice': 
  194. case 'group': 
  195. case 'sequence': 
  196. //$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement"); 
  197. $this->complexTypes[$this->currentComplexType]['compositor'] = $name; 
  198. //if($name == 'all' || $name == 'sequence') { 
  199. // $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; 
  200. //} 
  201. break; 
  202. case 'attribute': // complexType attribute 
  203. //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']); 
  204. $this->xdebug("parsing attribute:"); 
  205. $this->appendDebug($this->varDump($attrs)); 
  206. if (!isset($attrs['form'])) { 
  207. // TODO: handle globals 
  208. $attrs['form'] = $this->schemaInfo['attributeFormDefault']; 
  209. if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { 
  210. $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; 
  211. if (!strpos($v, ':')) { 
  212. // no namespace in arrayType attribute value... 
  213. if ($this->defaultNamespace[$pos]) { 
  214. // ...so use the default 
  215. $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; 
  216. if(isset($attrs['name'])) { 
  217. $this->attributes[$attrs['name']] = $attrs; 
  218. $aname = $attrs['name']; 
  219. } elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType') { 
  220. if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { 
  221. $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; 
  222. } else { 
  223. $aname = ''; 
  224. } elseif(isset($attrs['ref'])) { 
  225. $aname = $attrs['ref']; 
  226. $this->attributes[$attrs['ref']] = $attrs; 
  227.  
  228. if($this->currentComplexType) { // This should *always* be 
  229. $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs; 
  230. // arrayType attribute 
  231. if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType') { 
  232. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; 
  233. $prefix = $this->getPrefix($aname); 
  234. if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { 
  235. $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; 
  236. } else { 
  237. $v = ''; 
  238. if(strpos($v, '[, ]')) { 
  239. $this->complexTypes[$this->currentComplexType]['multidimensional'] = true; 
  240. $v = substr($v, 0, strpos($v, '[')); // clip the [] 
  241. if(!strpos($v, ':') && isset($this->typemap[$this->XMLSchemaVersion][$v])) { 
  242. $v = $this->XMLSchemaVersion.':'.$v; 
  243. $this->complexTypes[$this->currentComplexType]['arrayType'] = $v; 
  244. break; 
  245. case 'complexContent': // (optional) content for a complexType 
  246. $this->xdebug("do nothing for element $name"); 
  247. break; 
  248. case 'complexType': 
  249. array_push($this->complexTypeStack, $this->currentComplexType); 
  250. if(isset($attrs['name'])) { 
  251. // TODO: what is the scope of named complexTypes that appear 
  252. // nested within other c complexTypes? 
  253. $this->xdebug('processing named complexType '.$attrs['name']); 
  254. //$this->currentElement = false; 
  255. $this->currentComplexType = $attrs['name']; 
  256. $this->complexTypes[$this->currentComplexType] = $attrs; 
  257. $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType'; 
  258. // This is for constructs like 
  259. // <complexType name="ListOfString" base="soap:Array"> 
  260. // <sequence> 
  261. // <element name="string" type="xsd:string" 
  262. // minOccurs="0" maxOccurs="unbounded" /> 
  263. // </sequence> 
  264. // </complexType> 
  265. if(isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) { 
  266. $this->xdebug('complexType is unusual array'); 
  267. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; 
  268. } else { 
  269. $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; 
  270. } else { 
  271. $name = $this->CreateTypeName($this->currentElement); 
  272. $this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name); 
  273. $this->currentComplexType = $name; 
  274. //$this->currentElement = false; 
  275. $this->complexTypes[$this->currentComplexType] = $attrs; 
  276. $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType'; 
  277. // This is for constructs like 
  278. // <complexType name="ListOfString" base="soap:Array"> 
  279. // <sequence> 
  280. // <element name="string" type="xsd:string" 
  281. // minOccurs="0" maxOccurs="unbounded" /> 
  282. // </sequence> 
  283. // </complexType> 
  284. if(isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) { 
  285. $this->xdebug('complexType is unusual array'); 
  286. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; 
  287. } else { 
  288. $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; 
  289. $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false'; 
  290. break; 
  291. case 'element': 
  292. array_push($this->elementStack, $this->currentElement); 
  293. if (!isset($attrs['form'])) { 
  294. if ($this->currentComplexType) { 
  295. $attrs['form'] = $this->schemaInfo['elementFormDefault']; 
  296. } else { 
  297. // global 
  298. $attrs['form'] = 'qualified'; 
  299. if(isset($attrs['type'])) { 
  300. $this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']); 
  301. if (! $this->getPrefix($attrs['type'])) { 
  302. if ($this->defaultNamespace[$pos]) { 
  303. $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type']; 
  304. $this->xdebug('used default namespace to make type ' . $attrs['type']); 
  305. // This is for constructs like 
  306. // <complexType name="ListOfString" base="soap:Array"> 
  307. // <sequence> 
  308. // <element name="string" type="xsd:string" 
  309. // minOccurs="0" maxOccurs="unbounded" /> 
  310. // </sequence> 
  311. // </complexType> 
  312. if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') { 
  313. $this->xdebug('arrayType for unusual array is ' . $attrs['type']); 
  314. $this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type']; 
  315. $this->currentElement = $attrs['name']; 
  316. $ename = $attrs['name']; 
  317. } elseif(isset($attrs['ref'])) { 
  318. $this->xdebug("processing element as ref to ".$attrs['ref']); 
  319. $this->currentElement = "ref to ".$attrs['ref']; 
  320. $ename = $this->getLocalPart($attrs['ref']); 
  321. } else { 
  322. $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']); 
  323. $this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type); 
  324. $this->currentElement = $attrs['name']; 
  325. $attrs['type'] = $this->schemaTargetNamespace . ':' . $type; 
  326. $ename = $attrs['name']; 
  327. if (isset($ename) && $this->currentComplexType) { 
  328. $this->xdebug("add element $ename to complexType $this->currentComplexType"); 
  329. $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs; 
  330. } elseif (!isset($attrs['ref'])) { 
  331. $this->xdebug("add element $ename to elements array"); 
  332. $this->elements[ $attrs['name'] ] = $attrs; 
  333. $this->elements[ $attrs['name'] ]['typeClass'] = 'element'; 
  334. break; 
  335. case 'enumeration': // restriction value list member 
  336. $this->xdebug('enumeration ' . $attrs['value']); 
  337. if ($this->currentSimpleType) { 
  338. $this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value']; 
  339. } elseif ($this->currentComplexType) { 
  340. $this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value']; 
  341. break; 
  342. case 'extension': // simpleContent or complexContent type extension 
  343. $this->xdebug('extension ' . $attrs['base']); 
  344. if ($this->currentComplexType) { 
  345. $ns = $this->getPrefix($attrs['base']); 
  346. if ($ns == '') { 
  347. $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base']; 
  348. } else { 
  349. $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base']; 
  350. } else { 
  351. $this->xdebug('no current complexType to set extensionBase'); 
  352. break; 
  353. case 'import': 
  354. if (isset($attrs['schemaLocation'])) { 
  355. $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']); 
  356. $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false); 
  357. } else { 
  358. $this->xdebug('import namespace ' . $attrs['namespace']); 
  359. $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true); 
  360. if (! $this->getPrefixFromNamespace($attrs['namespace'])) { 
  361. $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace']; 
  362. break; 
  363. case 'include': 
  364. if (isset($attrs['schemaLocation'])) { 
  365. $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']); 
  366. $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false); 
  367. } else { 
  368. $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute'); 
  369. break; 
  370. case 'list': // simpleType value list 
  371. $this->xdebug("do nothing for element $name"); 
  372. break; 
  373. case 'restriction': // simpleType, simpleContent or complexContent value restriction 
  374. $this->xdebug('restriction ' . $attrs['base']); 
  375. if($this->currentSimpleType) { 
  376. $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base']; 
  377. } elseif($this->currentComplexType) { 
  378. $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base']; 
  379. if(strstr($attrs['base'], ':') == ':Array') { 
  380. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; 
  381. break; 
  382. case 'schema': 
  383. $this->schemaInfo = $attrs; 
  384. $this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix); 
  385. if (isset($attrs['targetNamespace'])) { 
  386. $this->schemaTargetNamespace = $attrs['targetNamespace']; 
  387. if (!isset($attrs['elementFormDefault'])) { 
  388. $this->schemaInfo['elementFormDefault'] = 'unqualified'; 
  389. if (!isset($attrs['attributeFormDefault'])) { 
  390. $this->schemaInfo['attributeFormDefault'] = 'unqualified'; 
  391. break; 
  392. case 'simpleContent': // (optional) content for a complexType 
  393. if ($this->currentComplexType) { // This should *always* be 
  394. $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true'; 
  395. } else { 
  396. $this->xdebug("do nothing for element $name because there is no current complexType"); 
  397. break; 
  398. case 'simpleType': 
  399. array_push($this->simpleTypeStack, $this->currentSimpleType); 
  400. if(isset($attrs['name'])) { 
  401. $this->xdebug("processing simpleType for name " . $attrs['name']); 
  402. $this->currentSimpleType = $attrs['name']; 
  403. $this->simpleTypes[ $attrs['name'] ] = $attrs; 
  404. $this->simpleTypes[ $attrs['name'] ]['typeClass'] = 'simpleType'; 
  405. $this->simpleTypes[ $attrs['name'] ]['phpType'] = 'scalar'; 
  406. } else { 
  407. $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement); 
  408. $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name); 
  409. $this->currentSimpleType = $name; 
  410. //$this->currentElement = false; 
  411. $this->simpleTypes[$this->currentSimpleType] = $attrs; 
  412. $this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar'; 
  413. break; 
  414. case 'union': // simpleType type list 
  415. $this->xdebug("do nothing for element $name"); 
  416. break; 
  417. default: 
  418. $this->xdebug("do not have any logic to process element $name"); 
  419.  
  420. /** 
  421. * end-element handler 
  422. * @param string $parser XML parser object 
  423. * @param string $name element name 
  424. * @access private 
  425. */ 
  426. function schemaEndElement($parser, $name) { 
  427. // bring depth down a notch 
  428. $this->depth--; 
  429. // position of current element is equal to the last value left in depth_array for my depth 
  430. if(isset($this->depth_array[$this->depth])) { 
  431. $pos = $this->depth_array[$this->depth]; 
  432. // get element prefix 
  433. if ($prefix = $this->getPrefix($name)) { 
  434. // get unqualified name 
  435. $name = $this->getLocalPart($name); 
  436. } else { 
  437. $prefix = ''; 
  438. // move on... 
  439. if($name == 'complexType') { 
  440. $this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)')); 
  441. $this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType])); 
  442. $this->currentComplexType = array_pop($this->complexTypeStack); 
  443. //$this->currentElement = false; 
  444. if($name == 'element') { 
  445. $this->xdebug('done processing element ' . ($this->currentElement ? $this->currentElement : '(unknown)')); 
  446. $this->currentElement = array_pop($this->elementStack); 
  447. if($name == 'simpleType') { 
  448. $this->xdebug('done processing simpleType ' . ($this->currentSimpleType ? $this->currentSimpleType : '(unknown)')); 
  449. $this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType])); 
  450. $this->currentSimpleType = array_pop($this->simpleTypeStack); 
  451.  
  452. /** 
  453. * element content handler 
  454. * @param string $parser XML parser object 
  455. * @param string $data element content 
  456. * @access private 
  457. */ 
  458. function schemaCharacterData($parser, $data) { 
  459. $pos = $this->depth_array[$this->depth - 1]; 
  460. $this->message[$pos]['cdata'] .= $data; 
  461.  
  462. /** 
  463. * serialize the schema 
  464. * @access public 
  465. */ 
  466. function serializeSchema() { 
  467.  
  468. $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion); 
  469. $xml = ''; 
  470. // imports 
  471. if (sizeof($this->imports) > 0) { 
  472. foreach($this->imports as $ns => $list) { 
  473. foreach ($list as $ii) { 
  474. if ($ii['location'] != '') { 
  475. $xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n"; 
  476. } else { 
  477. $xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n"; 
  478. }  
  479. }  
  480. // complex types 
  481. foreach($this->complexTypes as $typeName => $attrs) { 
  482. $contentStr = ''; 
  483. // serialize child elements 
  484. if(isset($attrs['elements']) && (count($attrs['elements']) > 0)) { 
  485. foreach($attrs['elements'] as $element => $eParts) { 
  486. if(isset($eParts['ref'])) { 
  487. $contentStr .= " <$schemaPrefix:element ref=\"$element\"/>\n"; 
  488. } else { 
  489. $contentStr .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\""; 
  490. foreach ($eParts as $aName => $aValue) { 
  491. // handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable 
  492. if ($aName != 'name' && $aName != 'type') { 
  493. $contentStr .= " $aName=\"$aValue\""; 
  494. $contentStr .= "/>\n"; 
  495. // compositor wraps elements 
  496. if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) { 
  497. $contentStr = " <$schemaPrefix:$attrs[compositor]>\n".$contentStr." </$schemaPrefix:$attrs[compositor]>\n"; 
  498. // attributes 
  499. if(isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)) { 
  500. foreach($attrs['attrs'] as $attr => $aParts) { 
  501. $contentStr .= " <$schemaPrefix:attribute"; 
  502. foreach ($aParts as $a => $v) { 
  503. if ($a == 'ref' || $a == 'type') { 
  504. $contentStr .= " $a=\"".$this->contractQName($v).'"'; 
  505. } elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') { 
  506. $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl']; 
  507. $contentStr .= ' wsdl:arrayType="'.$this->contractQName($v).'"'; 
  508. } else { 
  509. $contentStr .= " $a=\"$v\""; 
  510. $contentStr .= "/>\n"; 
  511. // if restriction 
  512. if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != '') { 
  513. $contentStr = " <$schemaPrefix:restriction base=\"".$this->contractQName($attrs['restrictionBase'])."\">\n".$contentStr." </$schemaPrefix:restriction>\n"; 
  514. // complex or simple content 
  515. if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)) { 
  516. $contentStr = " <$schemaPrefix:complexContent>\n".$contentStr." </$schemaPrefix:complexContent>\n"; 
  517. // finalize complex type 
  518. if($contentStr != '') { 
  519. $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n".$contentStr." </$schemaPrefix:complexType>\n"; 
  520. } else { 
  521. $contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n"; 
  522. $xml .= $contentStr; 
  523. // simple types 
  524. if(isset($this->simpleTypes) && count($this->simpleTypes) > 0) { 
  525. foreach($this->simpleTypes as $typeName => $eParts) { 
  526. $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n <$schemaPrefix:restriction base=\"".$this->contractQName($eParts['type'])."\">\n"; 
  527. if (isset($eParts['enumeration'])) { 
  528. foreach ($eParts['enumeration'] as $e) { 
  529. $xml .= " <$schemaPrefix:enumeration value=\"$e\"/>\n"; 
  530. $xml .= " </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>"; 
  531. // elements 
  532. if(isset($this->elements) && count($this->elements) > 0) { 
  533. foreach($this->elements as $element => $eParts) { 
  534. $xml .= " <$schemaPrefix:element name=\"$element\" type=\"".$this->contractQName($eParts['type'])."\"/>\n"; 
  535. // attributes 
  536. if(isset($this->attributes) && count($this->attributes) > 0) { 
  537. foreach($this->attributes as $attr => $aParts) { 
  538. $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"".$this->contractQName($aParts['type'])."\"\n/>"; 
  539. // finish 'er up 
  540. $attr = ''; 
  541. foreach ($this->schemaInfo as $k => $v) { 
  542. if ($k == 'elementFormDefault' || $k == 'attributeFormDefault') { 
  543. $attr .= " $k=\"$v\""; 
  544. $el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n"; 
  545. foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) { 
  546. $el .= " xmlns:$nsp=\"$ns\""; 
  547. $xml = $el . ">\n".$xml."</$schemaPrefix:schema>\n"; 
  548. return $xml; 
  549.  
  550. /** 
  551. * adds debug data to the clas level debug string 
  552. * @param string $string debug data 
  553. * @access private 
  554. */ 
  555. function xdebug($string) { 
  556. $this->debug('<' . $this->schemaTargetNamespace . '> '.$string); 
  557.  
  558. /** 
  559. * get the PHP type of a user defined type in the schema 
  560. * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays 
  561. * returns false if no type exists, or not w/ the given namespace 
  562. * else returns a string that is either a native php type, or 'struct' 
  563. * @param string $type name of defined type 
  564. * @param string $ns namespace of type 
  565. * @return mixed 
  566. * @access public 
  567. * @deprecated 
  568. */ 
  569. function getPHPType($type, $ns) { 
  570. if(isset($this->typemap[$ns][$type])) { 
  571. //print "found type '$type' and ns $ns in typemap<br>"; 
  572. return $this->typemap[$ns][$type]; 
  573. } elseif(isset($this->complexTypes[$type])) { 
  574. //print "getting type '$type' and ns $ns from complexTypes array<br>"; 
  575. return $this->complexTypes[$type]['phpType']; 
  576. return false; 
  577.  
  578. /** 
  579. * returns an associative array of information about a given type 
  580. * returns false if no type exists by the given name 
  581. * For a complexType typeDef = array( 
  582. * 'restrictionBase' => '',  
  583. * 'phpType' => '',  
  584. * 'compositor' => '(sequence|all)',  
  585. * 'elements' => array(), // refs to elements array 
  586. * 'attrs' => array() // refs to attributes array 
  587. * ... and so on (see addComplexType) 
  588. * ) 
  589. * For simpleType or element, the array has different keys. 
  590. * @param string $type 
  591. * @return mixed 
  592. * @access public 
  593. * @see addComplexType 
  594. * @see addSimpleType 
  595. * @see addElement 
  596. */ 
  597. function getTypeDef($type) { 
  598. //$this->debug("in getTypeDef for type $type"); 
  599. if (substr($type, -1) == '^') { 
  600. $is_element = 1; 
  601. $type = substr($type, 0, -1); 
  602. } else { 
  603. $is_element = 0; 
  604.  
  605. if((! $is_element) && isset($this->complexTypes[$type])) { 
  606. $this->xdebug("in getTypeDef, found complexType $type"); 
  607. return $this->complexTypes[$type]; 
  608. } elseif((! $is_element) && isset($this->simpleTypes[$type])) { 
  609. $this->xdebug("in getTypeDef, found simpleType $type"); 
  610. if (!isset($this->simpleTypes[$type]['phpType'])) { 
  611. // get info for type to tack onto the simple type 
  612. // TODO: can this ever really apply (i.e. what is a simpleType really?) 
  613. $uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1); 
  614. $ns = substr($this->simpleTypes[$type]['type'], 0, strrpos($this->simpleTypes[$type]['type'], ':')); 
  615. $etype = $this->getTypeDef($uqType); 
  616. if ($etype) { 
  617. $this->xdebug("in getTypeDef, found type for simpleType $type:"); 
  618. $this->xdebug($this->varDump($etype)); 
  619. if (isset($etype['phpType'])) { 
  620. $this->simpleTypes[$type]['phpType'] = $etype['phpType']; 
  621. if (isset($etype['elements'])) { 
  622. $this->simpleTypes[$type]['elements'] = $etype['elements']; 
  623. return $this->simpleTypes[$type]; 
  624. } elseif(isset($this->elements[$type])) { 
  625. $this->xdebug("in getTypeDef, found element $type"); 
  626. if (!isset($this->elements[$type]['phpType'])) { 
  627. // get info for type to tack onto the element 
  628. $uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1); 
  629. $ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':')); 
  630. $etype = $this->getTypeDef($uqType); 
  631. if ($etype) { 
  632. $this->xdebug("in getTypeDef, found type for element $type:"); 
  633. $this->xdebug($this->varDump($etype)); 
  634. if (isset($etype['phpType'])) { 
  635. $this->elements[$type]['phpType'] = $etype['phpType']; 
  636. if (isset($etype['elements'])) { 
  637. $this->elements[$type]['elements'] = $etype['elements']; 
  638. if (isset($etype['extensionBase'])) { 
  639. $this->elements[$type]['extensionBase'] = $etype['extensionBase']; 
  640. } elseif ($ns == 'http://www.w3.org/2001/XMLSchema') { 
  641. $this->xdebug("in getTypeDef, element $type is an XSD type"); 
  642. $this->elements[$type]['phpType'] = 'scalar'; 
  643. return $this->elements[$type]; 
  644. } elseif(isset($this->attributes[$type])) { 
  645. $this->xdebug("in getTypeDef, found attribute $type"); 
  646. return $this->attributes[$type]; 
  647. } elseif (preg_match('/_ContainedType$/', $type)) { 
  648. $this->xdebug("in getTypeDef, have an untyped element $type"); 
  649. $typeDef['typeClass'] = 'simpleType'; 
  650. $typeDef['phpType'] = 'scalar'; 
  651. $typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string'; 
  652. return $typeDef; 
  653. $this->xdebug("in getTypeDef, did not find $type"); 
  654. return false; 
  655.  
  656. /** 
  657. * returns a sample serialization of a given type, or false if no type by the given name 
  658. * @param string $type name of type 
  659. * @return mixed 
  660. * @access public 
  661. * @deprecated 
  662. */ 
  663. function serializeTypeDef($type) { 
  664. //print "in sTD() for type $type<br>"; 
  665. if($typeDef = $this->getTypeDef($type)) { 
  666. $str .= '<'.$type; 
  667. if(is_array($typeDef['attrs'])) { 
  668. foreach($typeDef['attrs'] as $attName => $data) { 
  669. $str .= " $attName=\"{type = ".$data['type']."}\""; 
  670. $str .= " xmlns=\"".$this->schema['targetNamespace']."\""; 
  671. if(count($typeDef['elements']) > 0) { 
  672. $str .= ">"; 
  673. foreach($typeDef['elements'] as $element => $eData) { 
  674. $str .= $this->serializeTypeDef($element); 
  675. $str .= "</$type>"; 
  676. } elseif($typeDef['typeClass'] == 'element') { 
  677. $str .= "></$type>"; 
  678. } else { 
  679. $str .= "/>"; 
  680. return $str; 
  681. return false; 
  682.  
  683. /** 
  684. * returns HTML form elements that allow a user 
  685. * to enter values for creating an instance of the given type. 
  686. * @param string $name name for type instance 
  687. * @param string $type name of type 
  688. * @return string 
  689. * @access public 
  690. * @deprecated 
  691. */ 
  692. function typeToForm($name, $type) { 
  693. // get typedef 
  694. if($typeDef = $this->getTypeDef($type)) { 
  695. // if struct 
  696. if($typeDef['phpType'] == 'struct') { 
  697. $buffer .= '<table>'; 
  698. foreach($typeDef['elements'] as $child => $childDef) { 
  699. $buffer .= " 
  700. <tr><td align='right'>$childDef[name] (type: ".$this->getLocalPart($childDef['type'])."):</td> 
  701. <td><input type='text' name='parameters[".$name."][$childDef[name]]'></td></tr>"; 
  702. $buffer .= '</table>'; 
  703. // if array 
  704. } elseif($typeDef['phpType'] == 'array') { 
  705. $buffer .= '<table>'; 
  706. for($i=0;$i < 3; $i++) { 
  707. $buffer .= " 
  708. <tr><td align='right'>array item (type: $typeDef[arrayType]):</td> 
  709. <td><input type='text' name='parameters[".$name."][]'></td></tr>"; 
  710. $buffer .= '</table>'; 
  711. // if scalar 
  712. } else { 
  713. $buffer .= "<input type='text' name='parameters[$name]'>"; 
  714. } else { 
  715. $buffer .= "<input type='text' name='parameters[$name]'>"; 
  716. return $buffer; 
  717.  
  718. /** 
  719. * adds a complex type to the schema 
  720. *  
  721. * example: array 
  722. *  
  723. * addType( 
  724. * 'ArrayOfstring',  
  725. * 'complexType',  
  726. * 'array',  
  727. * '',  
  728. * 'SOAP-ENC:Array',  
  729. * array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType'=>'string[]'),  
  730. * 'xsd:string' 
  731. * ); 
  732. *  
  733. * example: PHP associative array ( SOAP Struct ) 
  734. *  
  735. * addType( 
  736. * 'SOAPStruct',  
  737. * 'complexType',  
  738. * 'struct',  
  739. * 'all',  
  740. * array('myVar'=> array('name'=>'myVar', 'type'=>'string') 
  741. * ); 
  742. *  
  743. * @param name 
  744. * @param typeClass (complexType|simpleType|attribute) 
  745. * @param phpType: currently supported are array and struct (php assoc array) 
  746. * @param compositor (all|sequence|choice) 
  747. * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) 
  748. * @param elements = array ( name = array(name=>'', type=>'') ) 
  749. * @param attrs = array( 
  750. * array( 
  751. * 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",  
  752. * "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]" 
  753. * ) 
  754. * ) 
  755. * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string) 
  756. * @access public 
  757. * @see getTypeDef 
  758. */ 
  759. function addComplexType($name, $typeClass='complexType', $phpType='array', $compositor='', $restrictionBase='', $elements=array(), $attrs=array(), $arrayType='') { 
  760. $this->complexTypes[$name] = array( 
  761. 'name' => $name,  
  762. 'typeClass' => $typeClass,  
  763. 'phpType' => $phpType,  
  764. 'compositor'=> $compositor,  
  765. 'restrictionBase' => $restrictionBase,  
  766. 'elements' => $elements,  
  767. 'attrs' => $attrs,  
  768. 'arrayType' => $arrayType 
  769. ); 
  770.  
  771. $this->xdebug("addComplexType $name:"); 
  772. $this->appendDebug($this->varDump($this->complexTypes[$name])); 
  773.  
  774. /** 
  775. * adds a simple type to the schema 
  776. * @param string $name 
  777. * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) 
  778. * @param string $typeClass (should always be simpleType) 
  779. * @param string $phpType (should always be scalar) 
  780. * @param array $enumeration array of values 
  781. * @access public 
  782. * @see nusoap_xmlschema 
  783. * @see getTypeDef 
  784. */ 
  785. function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) { 
  786. $this->simpleTypes[$name] = array( 
  787. 'name' => $name,  
  788. 'typeClass' => $typeClass,  
  789. 'phpType' => $phpType,  
  790. 'type' => $restrictionBase,  
  791. 'enumeration' => $enumeration 
  792. ); 
  793.  
  794. $this->xdebug("addSimpleType $name:"); 
  795. $this->appendDebug($this->varDump($this->simpleTypes[$name])); 
  796.  
  797. /** 
  798. * adds an element to the schema 
  799. * @param array $attrs attributes that must include name and type 
  800. * @see nusoap_xmlschema 
  801. * @access public 
  802. */ 
  803. function addElement($attrs) { 
  804. if (! $this->getPrefix($attrs['type'])) { 
  805. $attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type']; 
  806. $this->elements[ $attrs['name'] ] = $attrs; 
  807. $this->elements[ $attrs['name'] ]['typeClass'] = 'element'; 
  808.  
  809. $this->xdebug("addElement " . $attrs['name']); 
  810. $this->appendDebug($this->varDump($this->elements[ $attrs['name'] ]));