• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

webservice/soap/lib/class.wsdl.php

Go to the documentation of this file.
00001 <?php
00002 
00003 
00004 
00005 
00013 class wsdl extends nusoap_base {
00014         // URL or filename of the root of this WSDL
00015     var $wsdl; 
00016     // define internal arrays of bindings, ports, operations, messages, etc.
00017     var $schemas = array();
00018     var $currentSchema;
00019     var $message = array();
00020     var $complexTypes = array();
00021     var $messages = array();
00022     var $currentMessage;
00023     var $currentOperation;
00024     var $portTypes = array();
00025     var $currentPortType;
00026     var $bindings = array();
00027     var $currentBinding;
00028     var $ports = array();
00029     var $currentPort;
00030     var $opData = array();
00031     var $status = '';
00032     var $documentation = false;
00033     var $endpoint = ''; 
00034     // array of wsdl docs to import
00035     var $import = array(); 
00036     // parser vars
00037     var $parser;
00038     var $position = 0;
00039     var $depth = 0;
00040     var $depth_array = array();
00041         // for getting wsdl
00042         var $proxyhost = '';
00043     var $proxyport = '';
00044         var $proxyusername = '';
00045         var $proxypassword = '';
00046         var $timeout = 0;
00047         var $response_timeout = 30;
00048 
00061     function wsdl($wsdl = '',$proxyhost=false,$proxyport=false,$proxyusername=false,$proxypassword=false,$timeout=0,$response_timeout=30){
00062         $this->wsdl = $wsdl;
00063         $this->proxyhost = $proxyhost;
00064         $this->proxyport = $proxyport;
00065                 $this->proxyusername = $proxyusername;
00066                 $this->proxypassword = $proxypassword;
00067                 $this->timeout = $timeout;
00068                 $this->response_timeout = $response_timeout;
00069         
00070         // parse wsdl file
00071         if ($wsdl != "") {
00072             $this->debug('initial wsdl URL: ' . $wsdl);
00073             $this->parseWSDL($wsdl);
00074         }
00075         // imports
00076         // TODO: handle imports more properly, grabbing them in-line and nesting them
00077                 $imported_urls = array();
00078                 $imported = 1;
00079                 while ($imported > 0) {
00080                         $imported = 0;
00081                         // Schema imports
00082                         foreach ($this->schemas as $ns => $list) {
00083                                 foreach ($list as $xs) {
00084                                                 $wsdlparts = parse_url($this->wsdl);    // this is bogusly simple!
00085                                     foreach ($xs->imports as $ns2 => $list2) {
00086                                         for ($ii = 0; $ii < count($list2); $ii++) {
00087                                                 if (! $list2[$ii]['loaded']) {
00088                                                         $this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true;
00089                                                         $url = $list2[$ii]['location'];
00090                                                                         if ($url != '') {
00091                                                                                 $urlparts = parse_url($url);
00092                                                                                 if (!isset($urlparts['host'])) {
00093                                                                                         $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . 
00094                                                                                                         substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path'];
00095                                                                                 }
00096                                                                                 if (! in_array($url, $imported_urls)) {
00097                                                                         $this->parseWSDL($url);
00098                                                                         $imported++;
00099                                                                         $imported_urls[] = $url;
00100                                                                 }
00101                                                                         } else {
00102                                                                                 $this->debug("Unexpected scenario: empty URL for unloaded import");
00103                                                                         }
00104                                                                 }
00105                                                         }
00106                                     } 
00107                                 }
00108                         }
00109                         // WSDL imports
00110                                 $wsdlparts = parse_url($this->wsdl);    // this is bogusly simple!
00111                     foreach ($this->import as $ns => $list) {
00112                         for ($ii = 0; $ii < count($list); $ii++) {
00113                                 if (! $list[$ii]['loaded']) {
00114                                         $this->import[$ns][$ii]['loaded'] = true;
00115                                         $url = $list[$ii]['location'];
00116                                                         if ($url != '') {
00117                                                                 $urlparts = parse_url($url);
00118                                                                 if (!isset($urlparts['host'])) {
00119                                                                         $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . 
00120                                                                                         substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path'];
00121                                                                 }
00122                                                                 if (! in_array($url, $imported_urls)) {
00123                                                         $this->parseWSDL($url);
00124                                                         $imported++;
00125                                                         $imported_urls[] = $url;
00126                                                 }
00127                                                         } else {
00128                                                                 $this->debug("Unexpected scenario: empty URL for unloaded import");
00129                                                         }
00130                                                 }
00131                                         }
00132                     } 
00133                         }
00134         // add new data to operation data
00135         foreach($this->bindings as $binding => $bindingData) {
00136             if (isset($bindingData['operations']) && is_array($bindingData['operations'])) {
00137                 foreach($bindingData['operations'] as $operation => $data) {
00138                     $this->debug('post-parse data gathering for ' . $operation);
00139                     $this->bindings[$binding]['operations'][$operation]['input'] = 
00140                                                 isset($this->bindings[$binding]['operations'][$operation]['input']) ? 
00141                                                 array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[ $bindingData['portType'] ][$operation]['input']) :
00142                                                 $this->portTypes[ $bindingData['portType'] ][$operation]['input'];
00143                     $this->bindings[$binding]['operations'][$operation]['output'] = 
00144                                                 isset($this->bindings[$binding]['operations'][$operation]['output']) ?
00145                                                 array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[ $bindingData['portType'] ][$operation]['output']) :
00146                                                 $this->portTypes[ $bindingData['portType'] ][$operation]['output'];
00147                     if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ])){
00148                                                 $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ];
00149                                         }
00150                                         if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ])){
00151                                 $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ];
00152                     }
00153                                         if (isset($bindingData['style'])) {
00154                         $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style'];
00155                     }
00156                     $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : '';
00157                     $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[ $bindingData['portType'] ][$operation]['documentation']) ? $this->portTypes[ $bindingData['portType'] ][$operation]['documentation'] : '';
00158                     $this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : '';
00159                 } 
00160             } 
00161         }
00162     }
00163 
00170     function parseWSDL($wsdl = '')
00171     {
00172         if ($wsdl == '') {
00173             $this->debug('no wsdl passed to parseWSDL()!!');
00174             $this->setError('no wsdl passed to parseWSDL()!!');
00175             return false;
00176         }
00177         
00178         // parse $wsdl for url format
00179         $wsdl_props = parse_url($wsdl);
00180 
00181         if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) {
00182             $this->debug('getting WSDL http(s) URL ' . $wsdl);
00183                 // get wsdl
00184                 $tr = new soap_transport_http($wsdl);
00185                         $tr->request_method = 'GET';
00186                         $tr->useSOAPAction = false;
00187                         if($this->proxyhost && $this->proxyport){
00188                                 $tr->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword);
00189                         }
00190                         if (isset($wsdl_props['user'])) {
00191                 $tr->setCredentials($wsdl_props['user'],$wsdl_props['pass']);
00192             }
00193                         $wsdl_string = $tr->send('', $this->timeout, $this->response_timeout);
00194                         //$this->debug("WSDL request\n" . $tr->outgoing_payload);
00195                         //$this->debug("WSDL response\n" . $tr->incoming_payload);
00196                         $this->debug("transport debug data...\n" . $tr->debug_str);
00197                         // catch errors
00198                         if($err = $tr->getError() ){
00199                                 $errstr = 'HTTP ERROR: '.$err;
00200                                 $this->debug($errstr);
00201                     $this->setError($errstr);
00202                                 unset($tr);
00203                     return false;
00204                         }
00205                         unset($tr);
00206         } else {
00207             // $wsdl is not http(s), so treat it as a file URL or plain file path
00208                 if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'file') && isset($wsdl_props['path'])) {
00209                         $path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path'];
00210                 } else {
00211                         $path = $wsdl;
00212                 }
00213             $this->debug('getting WSDL file ' . $path);
00214             if ($fp = @fopen($path, 'r')) {
00215                 $wsdl_string = '';
00216                 while ($data = fread($fp, 32768)) {
00217                     $wsdl_string .= $data;
00218                 } 
00219                 fclose($fp);
00220             } else {
00221                 $errstr = "Bad path to WSDL file $path";
00222                 $this->debug($errstr);
00223                 $this->setError($errstr);
00224                 return false;
00225             } 
00226         }
00227         // end new code added
00228         // Create an XML parser.
00229         $this->parser = xml_parser_create(); 
00230         // Set the options for parsing the XML data.
00231         // xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
00232         xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); 
00233         // Set the object for the parser.
00234         xml_set_object($this->parser, $this); 
00235         // Set the element handlers for the parser.
00236         xml_set_element_handler($this->parser, 'start_element', 'end_element');
00237         xml_set_character_data_handler($this->parser, 'character_data');
00238         // Parse the XML file.
00239         if (!xml_parse($this->parser, $wsdl_string, true)) {
00240             // Display an error message.
00241             $errstr = sprintf(
00242                                 'XML error parsing WSDL from %s on line %d: %s',
00243                                 $wsdl,
00244                 xml_get_current_line_number($this->parser),
00245                 xml_error_string(xml_get_error_code($this->parser))
00246                 );
00247             $this->debug($errstr);
00248                         $this->debug("XML payload:\n" . $wsdl_string);
00249             $this->setError($errstr);
00250             return false;
00251         } 
00252                 // free the parser
00253         xml_parser_free($this->parser);
00254                 // catch wsdl parse errors
00255                 if($this->getError()){
00256                         return false;
00257                 }
00258         return true;
00259     } 
00260 
00269     function start_element($parser, $name, $attrs)
00270     {
00271         if ($this->status == 'schema') {
00272             $this->currentSchema->schemaStartElement($parser, $name, $attrs);
00273             $this->debug_str .= $this->currentSchema->debug_str;
00274             $this->currentSchema->debug_str = '';
00275         } elseif (ereg('schema$', $name)) {
00276             // $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")");
00277             $this->status = 'schema';
00278             $this->currentSchema = new xmlschema('', '', $this->namespaces);
00279             $this->currentSchema->schemaStartElement($parser, $name, $attrs);
00280             $this->debug_str .= $this->currentSchema->debug_str;
00281             $this->currentSchema->debug_str = '';
00282         } else {
00283             // position in the total number of elements, starting from 0
00284             $pos = $this->position++;
00285             $depth = $this->depth++; 
00286             // set self as current value for this depth
00287             $this->depth_array[$depth] = $pos;
00288             $this->message[$pos] = array('cdata' => ''); 
00289             // get element prefix
00290             if (ereg(':', $name)) {
00291                 // get ns prefix
00292                 $prefix = substr($name, 0, strpos($name, ':')); 
00293                 // get ns
00294                 $namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : ''; 
00295                 // get unqualified name
00296                 $name = substr(strstr($name, ':'), 1);
00297             } 
00298 
00299             if (count($attrs) > 0) {
00300                 foreach($attrs as $k => $v) {
00301                     // if ns declarations, add to class level array of valid namespaces
00302                     if (ereg("^xmlns", $k)) {
00303                         if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
00304                             $this->namespaces[$ns_prefix] = $v;
00305                         } else {
00306                             $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
00307                         } 
00308                         if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema') {
00309                             $this->XMLSchemaVersion = $v;
00310                             $this->namespaces['xsi'] = $v . '-instance';
00311                         } 
00312                     } //  
00313                     // expand each attribute
00314                     $k = strpos($k, ':') ? $this->expandQname($k) : $k;
00315                     if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') {
00316                         $v = strpos($v, ':') ? $this->expandQname($v) : $v;
00317                     } 
00318                     $eAttrs[$k] = $v;
00319                 } 
00320                 $attrs = $eAttrs;
00321             } else {
00322                 $attrs = array();
00323             } 
00324             // find status, register data
00325             switch ($this->status) {
00326                 case 'message':
00327                     if ($name == 'part') {
00328                         if (isset($attrs['type'])) {
00329                                     $this->debug("msg " . $this->currentMessage . ": found part $attrs[name]: " . implode(',', $attrs));
00330                                     $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
00331                                 } 
00332                                     if (isset($attrs['element'])) {
00333                                         $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'];
00334                                     } 
00335                                 } 
00336                                 break;
00337                             case 'portType':
00338                                 switch ($name) {
00339                                     case 'operation':
00340                                         $this->currentPortOperation = $attrs['name'];
00341                                         $this->debug("portType $this->currentPortType operation: $this->currentPortOperation");
00342                                         if (isset($attrs['parameterOrder'])) {
00343                                                 $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder'];
00344                                                 } 
00345                                                 break;
00346                                             case 'documentation':
00347                                                 $this->documentation = true;
00348                                                 break; 
00349                                             // merge input/output data
00350                                             default:
00351                                                 $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : '';
00352                                                 $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m;
00353                                                 break;
00354                                         } 
00355                                 break;
00356                                 case 'binding':
00357                                     switch ($name) {
00358                                         case 'binding': 
00359                                             // get ns prefix
00360                                             if (isset($attrs['style'])) {
00361                                             $this->bindings[$this->currentBinding]['prefix'] = $prefix;
00362                                                 } 
00363                                                 $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs);
00364                                                 break;
00365                                                 case 'header':
00366                                                     $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs;
00367                                                     break;
00368                                                 case 'operation':
00369                                                     if (isset($attrs['soapAction'])) {
00370                                                         $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
00371                                                     } 
00372                                                     if (isset($attrs['style'])) {
00373                                                         $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style'];
00374                                                     } 
00375                                                     if (isset($attrs['name'])) {
00376                                                         $this->currentOperation = $attrs['name'];
00377                                                         $this->debug("current binding operation: $this->currentOperation");
00378                                                         $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name'];
00379                                                         $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding;
00380                                                         $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : '';
00381                                                     } 
00382                                                     break;
00383                                                 case 'input':
00384                                                     $this->opStatus = 'input';
00385                                                     break;
00386                                                 case 'output':
00387                                                     $this->opStatus = 'output';
00388                                                     break;
00389                                                 case 'body':
00390                                                     if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) {
00391                                                         $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs);
00392                                                     } else {
00393                                                         $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
00394                                                     } 
00395                                                     break;
00396                                         } 
00397                                         break;
00398                                 case 'service':
00399                                         switch ($name) {
00400                                             case 'port':
00401                                                 $this->currentPort = $attrs['name'];
00402                                                 $this->debug('current port: ' . $this->currentPort);
00403                                                 $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']);
00404                                         
00405                                                 break;
00406                                             case 'address':
00407                                                 $this->ports[$this->currentPort]['location'] = $attrs['location'];
00408                                                 $this->ports[$this->currentPort]['bindingType'] = $namespace;
00409                                                 $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace;
00410                                                 $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location'];
00411                                                 break;
00412                                         } 
00413                                         break;
00414                         } 
00415                 // set status
00416                 switch ($name) {
00417                         case 'import':
00418                             if (isset($attrs['location'])) {
00419                     $this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false);
00420                     $this->debug('parsing import ' . $attrs['namespace']. ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]).')');
00421                                 } else {
00422                     $this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
00423                                         if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
00424                                                 $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
00425                                         }
00426                     $this->debug('parsing import ' . $attrs['namespace']. ' - [no location] (' . count($this->import[$attrs['namespace']]).')');
00427                                 }
00428                                 break;
00429                         //wait for schema
00430                         //case 'types':
00431                         //      $this->status = 'schema';
00432                         //      break;
00433                         case 'message':
00434                                 $this->status = 'message';
00435                                 $this->messages[$attrs['name']] = array();
00436                                 $this->currentMessage = $attrs['name'];
00437                                 break;
00438                         case 'portType':
00439                                 $this->status = 'portType';
00440                                 $this->portTypes[$attrs['name']] = array();
00441                                 $this->currentPortType = $attrs['name'];
00442                                 break;
00443                         case "binding":
00444                                 if (isset($attrs['name'])) {
00445                                 // get binding name
00446                                         if (strpos($attrs['name'], ':')) {
00447                                         $this->currentBinding = $this->getLocalPart($attrs['name']);
00448                                         } else {
00449                                         $this->currentBinding = $attrs['name'];
00450                                         } 
00451                                         $this->status = 'binding';
00452                                         $this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']);
00453                                         $this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']);
00454                                 } 
00455                                 break;
00456                         case 'service':
00457                                 $this->serviceName = $attrs['name'];
00458                                 $this->status = 'service';
00459                                 $this->debug('current service: ' . $this->serviceName);
00460                                 break;
00461                         case 'definitions':
00462                                 foreach ($attrs as $name => $value) {
00463                                         $this->wsdl_info[$name] = $value;
00464                                 } 
00465                                 break;
00466                         } 
00467                 } 
00468         } 
00469 
00477         function end_element($parser, $name){ 
00478                 // unset schema status
00479                 if (/*ereg('types$', $name) ||*/ ereg('schema$', $name)) {
00480                         $this->status = "";
00481                         $this->schemas[$this->currentSchema->schemaTargetNamespace][] = $this->currentSchema;
00482                 } 
00483                 if ($this->status == 'schema') {
00484                         $this->currentSchema->schemaEndElement($parser, $name);
00485                 } else {
00486                         // bring depth down a notch
00487                         $this->depth--;
00488                 } 
00489                 // end documentation
00490                 if ($this->documentation) {
00491                         //TODO: track the node to which documentation should be assigned; it can be a part, message, etc.
00492                         //$this->portTypes[$this->currentPortType][$this->currentPortOperation]['documentation'] = $this->documentation;
00493                         $this->documentation = false;
00494                 } 
00495         } 
00496 
00504         function character_data($parser, $data)
00505         {
00506                 $pos = isset($this->depth_array[$this->depth]) ? $this->depth_array[$this->depth] : 0;
00507                 if (isset($this->message[$pos]['cdata'])) {
00508                         $this->message[$pos]['cdata'] .= $data;
00509                 } 
00510                 if ($this->documentation) {
00511                         $this->documentation .= $data;
00512                 } 
00513         } 
00514         
00515         function getBindingData($binding)
00516         {
00517                 if (is_array($this->bindings[$binding])) {
00518                         return $this->bindings[$binding];
00519                 } 
00520         }
00521         
00529         function getOperations($bindingType = 'soap')
00530         {
00531                 $ops = array();
00532                 if ($bindingType == 'soap') {
00533                         $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
00534                 }
00535                 // loop thru ports
00536                 foreach($this->ports as $port => $portData) {
00537                         // binding type of port matches parameter
00538                         if ($portData['bindingType'] == $bindingType) {
00539                                 //$this->debug("getOperations for port $port");
00540                                 //$this->debug("port data: " . $this->varDump($portData));
00541                                 //$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ]));
00542                                 // merge bindings
00543                                 if (isset($this->bindings[ $portData['binding'] ]['operations'])) {
00544                                         $ops = array_merge ($ops, $this->bindings[ $portData['binding'] ]['operations']);
00545                                 }
00546                         }
00547                 } 
00548                 return $ops;
00549         } 
00550         
00559         function getOperationData($operation, $bindingType = 'soap')
00560         {
00561                 if ($bindingType == 'soap') {
00562                         $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
00563                 }
00564                 // loop thru ports
00565                 foreach($this->ports as $port => $portData) {
00566                         // binding type of port matches parameter
00567                         if ($portData['bindingType'] == $bindingType) {
00568                                 // get binding
00569                                 //foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
00570                                 foreach(array_keys($this->bindings[ $portData['binding'] ]['operations']) as $bOperation) {
00571                                         if ($operation == $bOperation) {
00572                                                 $opData = $this->bindings[ $portData['binding'] ]['operations'][$operation];
00573                                             return $opData;
00574                                         } 
00575                                 } 
00576                         }
00577                 } 
00578         }
00579         
00598         function getTypeDef($type, $ns) {
00599                 if ((! $ns) && isset($this->namespaces['tns'])) {
00600                         $ns = $this->namespaces['tns'];
00601                 }
00602                 if (isset($this->schemas[$ns])) {
00603                         foreach ($this->schemas[$ns] as $xs) {
00604                                 $t = $xs->getTypeDef($type);
00605                                 $this->debug_str .= $xs->debug_str;
00606                                 $xs->debug_str = '';
00607                                 if ($t) {
00608                                         return $t;
00609                                 }
00610                         }
00611                 }
00612                 return false;
00613         }
00614 
00621         function serialize()
00622         {
00623                 $xml = '<?xml version="1.0" encoding="ISO-8859-1"?><definitions';
00624                 foreach($this->namespaces as $k => $v) {
00625                         $xml .= " xmlns:$k=\"$v\"";
00626                 } 
00627                 // 10.9.02 - add poulter fix for wsdl and tns declarations
00628                 if (isset($this->namespaces['wsdl'])) {
00629                         $xml .= " xmlns=\"" . $this->namespaces['wsdl'] . "\"";
00630                 } 
00631                 if (isset($this->namespaces['tns'])) {
00632                         $xml .= " targetNamespace=\"" . $this->namespaces['tns'] . "\"";
00633                 } 
00634                 $xml .= '>'; 
00635                 // imports
00636                 if (sizeof($this->import) > 0) {
00637                         foreach($this->import as $ns => $list) {
00638                                 foreach ($list as $ii) {
00639                                         if ($ii['location'] != '') {
00640                                                 $xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />';
00641                                         } else {
00642                                                 $xml .= '<import namespace="' . $ns . '" />';
00643                                         }
00644                                 }
00645                         } 
00646                 } 
00647                 // types
00648                 if (count($this->schemas)>=1) {
00649                         $xml .= '<types>';
00650                         foreach ($this->schemas as $ns => $list) {
00651                                 foreach ($list as $xs) {
00652                                         $xml .= $xs->serializeSchema();
00653                                 }
00654                         }
00655                         $xml .= '</types>';
00656                 } 
00657                 // messages
00658                 if (count($this->messages) >= 1) {
00659                         foreach($this->messages as $msgName => $msgParts) {
00660                                 $xml .= '<message name="' . $msgName . '">';
00661                                 if(is_array($msgParts)){
00662                                         foreach($msgParts as $partName => $partType) {
00663                                                 // print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>';
00664                                                 if (strpos($partType, ':')) {
00665                                                     $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType));
00666                                                 } elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) {
00667                                                     // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>';
00668                                                     $typePrefix = 'xsd';
00669                                                 } else {
00670                                                     foreach($this->typemap as $ns => $types) {
00671                                                         if (isset($types[$partType])) {
00672                                                             $typePrefix = $this->getPrefixFromNamespace($ns);
00673                                                         } 
00674                                                     } 
00675                                                     if (!isset($typePrefix)) {
00676                                                         die("$partType has no namespace!");
00677                                                     } 
00678                                                 } 
00679                                                 $xml .= '<part name="' . $partName . '" type="' . $typePrefix . ':' . $this->getLocalPart($partType) . '" />';
00680                                         }
00681                                 }
00682                                 $xml .= '</message>';
00683                         } 
00684                 } 
00685                 // bindings & porttypes
00686                 if (count($this->bindings) >= 1) {
00687                         $binding_xml = '';
00688                         $portType_xml = '';
00689                         foreach($this->bindings as $bindingName => $attrs) {
00690                                 $binding_xml .= '<binding name="' . $bindingName . '" type="tns:' . $attrs['portType'] . '">';
00691                                 $binding_xml .= '<soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>';
00692                                 $portType_xml .= '<portType name="' . $attrs['portType'] . '">';
00693                                 foreach($attrs['operations'] as $opName => $opParts) {
00694                                         $binding_xml .= '<operation name="' . $opName . '">';
00695                                         $binding_xml .= '<soap:operation soapAction="' . $opParts['soapAction'] . '" style="'. $attrs['style'] . '"/>';
00696                                         if (isset($opParts['input']['encodingStyle']) && $opParts['input']['encodingStyle'] != '') {
00697                                                 $enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"';
00698                                         } else {
00699                                                 $enc_style = '';
00700                                         }
00701                                         $binding_xml .= '<input><soap:body use="' . $opParts['input']['use'] . '" namespace="' . $opParts['input']['namespace'] . '"' . $enc_style . '/></input>';
00702                                         if (isset($opParts['output']['encodingStyle']) && $opParts['output']['encodingStyle'] != '') {
00703                                                 $enc_style = ' encodingStyle="' . $opParts['output']['encodingStyle'] . '"';
00704                                         } else {
00705                                                 $enc_style = '';
00706                                         }
00707                                         $binding_xml .= '<output><soap:body use="' . $opParts['output']['use'] . '" namespace="' . $opParts['output']['namespace'] . '"' . $enc_style . '/></output>';
00708                                         $binding_xml .= '</operation>';
00709                                         $portType_xml .= '<operation name="' . $opParts['name'] . '"';
00710                                         if (isset($opParts['parameterOrder'])) {
00711                                             $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"';
00712                                         } 
00713                                         $portType_xml .= '>';
00714                                         if(isset($opParts['documentation']) && $opParts['documentation'] != '') {
00715                                                 $portType_xml .= '<documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>';
00716                                         }
00717                                         $portType_xml .= '<input message="tns:' . $opParts['input']['message'] . '"/>';
00718                                         $portType_xml .= '<output message="tns:' . $opParts['output']['message'] . '"/>';
00719                                         $portType_xml .= '</operation>';
00720                                 } 
00721                                 $portType_xml .= '</portType>';
00722                                 $binding_xml .= '</binding>';
00723                         } 
00724                         $xml .= $portType_xml . $binding_xml;
00725                 } 
00726                 // services
00727                 $xml .= '<service name="' . $this->serviceName . '">';
00728                 if (count($this->ports) >= 1) {
00729                         foreach($this->ports as $pName => $attrs) {
00730                                 $xml .= '<port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">';
00731                                 $xml .= '<soap:address location="' . $attrs['location'] . '"/>';
00732                                 $xml .= '</port>';
00733                         } 
00734                 } 
00735                 $xml .= '</service>';
00736                 return $xml . '</definitions>';
00737         } 
00738         
00750         function serializeRPCParameters($operation, $direction, $parameters)
00751         {
00752                 $this->debug('in serializeRPCParameters with operation '.$operation.', direction '.$direction.' and '.count($parameters).' param(s), and xml schema version ' . $this->XMLSchemaVersion); 
00753                 
00754                 if ($direction != 'input' && $direction != 'output') {
00755                         $this->debug('The value of the \$direction argument needs to be either "input" or "output"');
00756                         $this->setError('The value of the \$direction argument needs to be either "input" or "output"');
00757                         return false;
00758                 } 
00759                 if (!$opData = $this->getOperationData($operation)) {
00760                         $this->debug('Unable to retrieve WSDL data for operation: ' . $operation);
00761                         $this->setError('Unable to retrieve WSDL data for operation: ' . $operation);
00762                         return false;
00763                 }
00764                 $this->debug($this->varDump($opData));
00765 
00766                 // Get encoding style for output and set to current
00767                 $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
00768                 if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
00769                         $encodingStyle = $opData['output']['encodingStyle'];
00770                         $enc_style = $encodingStyle;
00771                 }
00772 
00773                 // set input params
00774                 $xml = '';
00775                 if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
00776                         
00777                         $use = $opData[$direction]['use'];
00778                         $this->debug("use=$use");
00779                         $this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)');
00780                         if (is_array($parameters)) {
00781                                 $parametersArrayType = $this->isArraySimpleOrStruct($parameters);
00782                                 $this->debug('have ' . $parametersArrayType . ' parameters');
00783                                 foreach($opData[$direction]['parts'] as $name => $type) {
00784                                         $this->debug('serializing part "'.$name.'" of type "'.$type.'"');
00785                                         // Track encoding style
00786                                         if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
00787                                                 $encodingStyle = $opData[$direction]['encodingStyle'];                  
00788                                                 $enc_style = $encodingStyle;
00789                                         } else {
00790                                                 $enc_style = false;
00791                                         }
00792                                         // NOTE: add error handling here
00793                                         // if serializeType returns false, then catch global error and fault
00794                                         if ($parametersArrayType == 'arraySimple') {
00795                                                 $p = array_shift($parameters);
00796                                                 $this->debug('calling serializeType w/indexed param');
00797                                                 $xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
00798                                         } elseif (isset($parameters[$name])) {
00799                                                 $this->debug('calling serializeType w/named param');
00800                                                 $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
00801                                         } else {
00802                                                 // TODO: only send nillable
00803                                                 $this->debug('calling serializeType w/null param');
00804                                                 $xml .= $this->serializeType($name, $type, null, $use, $enc_style);
00805                                         }
00806                                 }
00807                         } else {
00808                                 $this->debug('no parameters passed.');
00809                         }
00810                 }
00811                 return $xml;
00812         } 
00813         
00825         function serializeParameters($operation, $direction, $parameters)
00826         {
00827                 $this->debug('in serializeParameters with operation '.$operation.', direction '.$direction.' and '.count($parameters).' param(s), and xml schema version ' . $this->XMLSchemaVersion); 
00828                 
00829                 if ($direction != 'input' && $direction != 'output') {
00830                         $this->debug('The value of the \$direction argument needs to be either "input" or "output"');
00831                         $this->setError('The value of the \$direction argument needs to be either "input" or "output"');
00832                         return false;
00833                 } 
00834                 if (!$opData = $this->getOperationData($operation)) {
00835                         $this->debug('Unable to retrieve WSDL data for operation: ' . $operation);
00836                         $this->setError('Unable to retrieve WSDL data for operation: ' . $operation);
00837                         return false;
00838                 }
00839                 $this->debug($this->varDump($opData));
00840                 
00841                 // Get encoding style for output and set to current
00842                 $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
00843                 if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
00844                         $encodingStyle = $opData['output']['encodingStyle'];
00845                         $enc_style = $encodingStyle;
00846                 }
00847                 
00848                 // set input params
00849                 $xml = '';
00850                 if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
00851                         
00852                         $use = $opData[$direction]['use'];
00853                         $this->debug("use=$use");
00854                         $this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)');
00855                         if (is_array($parameters)) {
00856                                 $parametersArrayType = $this->isArraySimpleOrStruct($parameters);
00857                                 $this->debug('have ' . $parametersArrayType . ' parameters');
00858                                 foreach($opData[$direction]['parts'] as $name => $type) {
00859                                         $this->debug('serializing part "'.$name.'" of type "'.$type.'"');
00860                                         // Track encoding style
00861                                         if(isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
00862                                                 $encodingStyle = $opData[$direction]['encodingStyle'];                  
00863                                                 $enc_style = $encodingStyle;
00864                                         } else {
00865                                                 $enc_style = false;
00866                                         }
00867                                         // NOTE: add error handling here
00868                                         // if serializeType returns false, then catch global error and fault
00869                                         if ($parametersArrayType == 'arraySimple') {
00870                                                 $p = array_shift($parameters);
00871                                                 $this->debug('calling serializeType w/indexed param');
00872                                                 $xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
00873                                         } elseif (isset($parameters[$name])) {
00874                                                 $this->debug('calling serializeType w/named param');
00875                                                 $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
00876                                         } else {
00877                                                 // TODO: only send nillable
00878                                                 $this->debug('calling serializeType w/null param');
00879                                                 $xml .= $this->serializeType($name, $type, null, $use, $enc_style);
00880                                         }
00881                                 }
00882                         } else {
00883                                 $this->debug('no parameters passed.');
00884                         }
00885                 }
00886                 return $xml;
00887         } 
00888         
00900         function serializeType($name, $type, $value, $use='encoded', $encodingStyle=false)
00901         {
00902                 $this->debug("in serializeType: $name, $type, $value, $use, $encodingStyle");
00903                 if($use == 'encoded' && $encodingStyle) {
00904                         $encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"';
00905                 }
00906 
00907                 // if a soap_val has been supplied, let its type override the WSDL
00908         if (is_object($value) && get_class($value) == 'soapval') {
00909                 // TODO: get attributes from soapval?
00910                 if ($value->type_ns) {
00911                         $type = $value->type_ns . ':' . $value->type;
00912                 } else {
00913                         $type = $value->type;
00914                 }
00915                 $value = $value->value;
00916                 $forceType = true;
00917                 $this->debug("in serializeType: soapval overrides type to $type, value to $value");
00918         } else {
00919                 $forceType = false;
00920         }
00921 
00922                 $xml = '';
00923                 if (strpos($type, ':')) {
00924                         $uqType = substr($type, strrpos($type, ':') + 1);
00925                         $ns = substr($type, 0, strrpos($type, ':'));
00926                         $this->debug("got a prefixed type: $uqType, $ns");
00927                         if ($this->getNamespaceFromPrefix($ns)) {
00928                                 $ns = $this->getNamespaceFromPrefix($ns);
00929                                 $this->debug("expanded prefixed type: $uqType, $ns");
00930                         }
00931 
00932                         if($ns == $this->XMLSchemaVersion){
00933                                 
00934                                 if (is_null($value)) {
00935                                         if ($use == 'literal') {
00936                                                 // TODO: depends on nillable
00937                                                 return "<$name/>";
00938                                         } else {
00939                                                 return "<$name xsi:nil=\"true\"/>";
00940                                         }
00941                                 }
00942                         if ($uqType == 'boolean' && !$value) {
00943                                         $value = 'false';
00944                                 } elseif ($uqType == 'boolean') {
00945                                         $value = 'true';
00946                                 } 
00947                                 if ($uqType == 'string' && gettype($value) == 'string') {
00948                                         $value = $this->expandEntities($value);
00949                                 } 
00950                                 // it's a scalar
00951                                 // TODO: what about null/nil values?
00952                                 // check type isn't a custom type extending xmlschema namespace
00953                                 if (!$this->getTypeDef($uqType, $ns)) {
00954                                         if ($use == 'literal') {
00955                                                 if ($forceType) {
00956                                                         return "<$name xsi:type=\"" . $this->getPrefixFromNamespace($this->XMLSchemaVersion) . ":$uqType\">$value</$name>";
00957                                                 } else {
00958                                                         return "<$name>$value</$name>";
00959                                                 }
00960                                         } else {
00961                                                 return "<$name xsi:type=\"" . $this->getPrefixFromNamespace($this->XMLSchemaVersion) . ":$uqType\"$encodingStyle>$value</$name>";
00962                                         }
00963                                 }
00964                         } else if ($ns == 'http://xml.apache.org/xml-soap') {
00965                                 if ($uqType == 'Map') {
00966                                         $contents = '';
00967                                         foreach($value as $k => $v) {
00968                                                 $this->debug("serializing map element: key $k, value $v");
00969                                                 $contents .= '<item>';
00970                                                 $contents .= $this->serialize_val($k,'key',false,false,false,false,$use);
00971                                                 $contents .= $this->serialize_val($v,'value',false,false,false,false,$use);
00972                                                 $contents .= '</item>';
00973                                         }
00974                                         if ($use == 'literal') {
00975                                                 if ($forceType) {
00976                                                 return "<$name xsi:type=\"" . $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap') . ":$uqType\">$contents</$name>";
00977                                                 } else {
00978                                                         return "<$name>$contents</$name>";
00979                                                 }
00980                                         } else {
00981                                                 return "<$name xsi:type=\"" . $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap') . ":$uqType\"$encodingStyle>$contents</$name>";
00982                                         }
00983                                 }
00984                         }
00985                 } else {
00986                         $this->debug("No namespace for type $type");
00987                         $ns = '';
00988                         $uqType = $type;
00989                 }
00990                 if(!$typeDef = $this->getTypeDef($uqType, $ns)){
00991                         $this->setError("$type ($uqType) is not a supported type.");
00992                         $this->debug("$type ($uqType) is not a supported type.");
00993                         return false;
00994                 } else {
00995                         foreach($typeDef as $k => $v) {
00996                                 $this->debug("typedef, $k: $v");
00997                         }
00998                 }
00999                 $phpType = $typeDef['phpType'];
01000                 $this->debug("serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '') ); 
01001                 // if php type == struct, map value to the <all> element names
01002                 if ($phpType == 'struct') {
01003                         if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') {
01004                                 $elementName = $uqType;
01005                                 if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
01006                                         $elementNS = " xmlns=\"$ns\"";
01007                                 }
01008                         } else {
01009                                 $elementName = $name;
01010                                 $elementNS = '';
01011                         }
01012                         if (is_null($value)) {
01013                                 if ($use == 'literal') {
01014                                         // TODO: depends on nillable
01015                                         return "<$elementName$elementNS/>";
01016                                 } else {
01017                                         return "<$elementName$elementNS xsi:nil=\"true\"/>";
01018                                 }
01019                         }
01020                         if ($use == 'literal') {
01021                                 if ($forceType) {
01022                                         $xml = "<$elementName$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">";
01023                                 } else {
01024                                         $xml = "<$elementName$elementNS>";
01025                                 }
01026                         } else {
01027                                 $xml = "<$elementName$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>";
01028                         }
01029                         
01030                         if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
01031                                 if (is_array($value)) {
01032                                         $xvalue = $value;
01033                                 } elseif (is_object($value)) {
01034                                         $xvalue = get_object_vars($value);
01035                                 } else {
01036                                         $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
01037                                         $xvalue = array();
01038                                 }
01039                                 // toggle whether all elements are present - ideally should validate against schema
01040                                 if(count($typeDef['elements']) != count($xvalue)){
01041                                         $optionals = true;
01042                                 }
01043                                 foreach($typeDef['elements'] as $eName => $attrs) {
01044                                         // if user took advantage of a minOccurs=0, then only serialize named parameters
01045                                         if(isset($optionals) && !isset($xvalue[$eName])){
01046                                                 // do nothing
01047                                         } else {
01048                                                 // get value
01049                                                 if (isset($xvalue[$eName])) {
01050                                                     $v = $xvalue[$eName];
01051                                                 } else {
01052                                                     $v = null;
01053                                                 }
01054                                                 // TODO: if maxOccurs > 1 (not just unbounded), then allow serialization of an array
01055                                                 if (isset($attrs['maxOccurs']) && $attrs['maxOccurs'] == 'unbounded' && isset($v) && is_array($v) && $this->isArraySimpleOrStruct($v) == 'arraySimple') {
01056                                                         $vv = $v;
01057                                                         foreach ($vv as $k => $v) {
01058                                                                 if (isset($attrs['type'])) {
01059                                                                         // serialize schema-defined type
01060                                                                     $xml .= $this->serializeType($eName, $attrs['type'], $v, $use, $encodingStyle);
01061                                                                 } else {
01062                                                                         // serialize generic type
01063                                                                     $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
01064                                                                     $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
01065                                                                 }
01066                                                         }
01067                                                 } else {
01068                                                         if (isset($attrs['type'])) {
01069                                                                 // serialize schema-defined type
01070                                                             $xml .= $this->serializeType($eName, $attrs['type'], $v, $use, $encodingStyle);
01071                                                         } else {
01072                                                                 // serialize generic type
01073                                                             $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
01074                                                             $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
01075                                                         }
01076                                                 }
01077                                         }
01078                                 } 
01079                         } else {
01080                                 $this->debug("Expected elements for XML Schema type $ns:$uqType");
01081                         }
01082                         $xml .= "</$elementName>";
01083                 } elseif ($phpType == 'array') {
01084                         if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
01085                                 $elementNS = " xmlns=\"$ns\"";
01086                         } else {
01087                                 $elementNS = '';
01088                         }
01089                         if (is_null($value)) {
01090                                 if ($use == 'literal') {
01091                                         // TODO: depends on nillable
01092                                         return "<$name$elementNS/>";
01093                                 } else {
01094                                         return "<$name$elementNS xsi:nil=\"true\"/>";
01095                                 }
01096                         }
01097                         if (isset($typeDef['multidimensional'])) {
01098                                 $nv = array();
01099                                 foreach($value as $v) {
01100                                         $cols = ',' . sizeof($v);
01101                                         $nv = array_merge($nv, $v);
01102                                 } 
01103                                 $value = $nv;
01104                         } else {
01105                                 $cols = '';
01106                         } 
01107                         if (is_array($value) && sizeof($value) >= 1) {
01108                                 $rows = sizeof($value);
01109                                 $contents = '';
01110                                 foreach($value as $k => $v) {
01111                                         $this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]");
01112                                         //if (strpos($typeDef['arrayType'], ':') ) {
01113                                         if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) {
01114                                             $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);
01115                                         } else {
01116                                             $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
01117                                         } 
01118                                 }
01119                                 $this->debug('contents: '.$this->varDump($contents));
01120                         } else {
01121                                 $rows = 0;
01122                                 $contents = null;
01123                         }
01124                         // TODO: for now, an empty value will be serialized as a zero element
01125                         // array.  Revisit this when coding the handling of null/nil values.
01126                         if ($use == 'literal') {
01127                                 $xml = "<$name$elementNS>"
01128                                         .$contents
01129                                         ."</$name>";
01130                         } else {
01131                                 $xml = "<$name$elementNS xsi:type=\"".$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/').':Array" '.
01132                                         $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/')
01133                                         .':arrayType="'
01134                                         .$this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType']))
01135                                         .":".$this->getLocalPart($typeDef['arrayType'])."[$rows$cols]\">"
01136                                         .$contents
01137                                         ."</$name>";
01138                         }
01139                 } elseif ($phpType == 'scalar') {
01140                         if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
01141                                 $elementNS = " xmlns=\"$ns\"";
01142                         } else {
01143                                 $elementNS = '';
01144                         }
01145                         if ($use == 'literal') {
01146                                 if ($forceType) {
01147                                         return "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
01148                                 } else {
01149                                         return "<$name$elementNS>$value</$name>";
01150                                 }
01151                         } else {
01152                                 return "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
01153                         }
01154                 }
01155                 $this->debug('returning: '.$this->varDump($xml));
01156                 return $xml;
01157         }
01158         
01178         function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType='') {
01179                 if (count($elements) > 0) {
01180                 foreach($elements as $n => $e){
01181                     // expand each element
01182                     foreach ($e as $k => $v) {
01183                             $k = strpos($k,':') ? $this->expandQname($k) : $k;
01184                             $v = strpos($v,':') ? $this->expandQname($v) : $v;
01185                             $ee[$k] = $v;
01186                         }
01187                         $eElements[$n] = $ee;
01188                 }
01189                 $elements = $eElements;
01190                 }
01191                 
01192                 if (count($attrs) > 0) {
01193                 foreach($attrs as $n => $a){
01194                     // expand each attribute
01195                     foreach ($a as $k => $v) {
01196                             $k = strpos($k,':') ? $this->expandQname($k) : $k;
01197                             $v = strpos($v,':') ? $this->expandQname($v) : $v;
01198                             $aa[$k] = $v;
01199                         }
01200                         $eAttrs[$n] = $aa;
01201                 }
01202                 $attrs = $eAttrs;
01203                 }
01204 
01205                 $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
01206                 $arrayType = strpos($arrayType,':') ? $this->expandQname($arrayType) : $arrayType;
01207 
01208                 $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
01209                 $this->schemas[$typens][0]->addComplexType($name,$typeClass,$phpType,$compositor,$restrictionBase,$elements,$attrs,$arrayType);
01210         }
01211 
01222         function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar') {
01223                 $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
01224 
01225                 $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
01226                 $this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType);
01227         }
01228 
01242         function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = ''){
01243                 if ($style == 'rpc' && $use == 'encoded') {
01244                         $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
01245                 } else {
01246                         $encodingStyle = '';
01247                 } 
01248                 // get binding
01249                 $this->bindings[ $this->serviceName . 'Binding' ]['operations'][$name] =
01250                 array(
01251                 'name' => $name,
01252                 'binding' => $this->serviceName . 'Binding',
01253                 'endpoint' => $this->endpoint,
01254                 'soapAction' => $soapaction,
01255                 'style' => $style,
01256                 'input' => array(
01257                         'use' => $use,
01258                         'namespace' => $namespace,
01259                         'encodingStyle' => $encodingStyle,
01260                         'message' => $name . 'Request',
01261                         'parts' => $in),
01262                 'output' => array(
01263                         'use' => $use,
01264                         'namespace' => $namespace,
01265                         'encodingStyle' => $encodingStyle,
01266                         'message' => $name . 'Response',
01267                         'parts' => $out),
01268                 'namespace' => $namespace,
01269                 'transport' => 'http://schemas.xmlsoap.org/soap/http',
01270                 'documentation' => $documentation); 
01271                 // add portTypes
01272                 // add messages
01273                 if($in)
01274                 {
01275                         foreach($in as $pName => $pType)
01276                         {
01277                                 if(strpos($pType,':')) {
01278                                         $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType);
01279                                 }
01280                                 $this->messages[$name.'Request'][$pName] = $pType;
01281                         }
01282                 } else {
01283             $this->messages[$name.'Request']= '0';
01284         }
01285                 if($out)
01286                 {
01287                         foreach($out as $pName => $pType)
01288                         {
01289                                 if(strpos($pType,':')) {
01290                                         $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType);
01291                                 }
01292                                 $this->messages[$name.'Response'][$pName] = $pType;
01293                         }
01294                 } else {
01295             $this->messages[$name.'Response']= '0';
01296         }
01297                 return true;
01298         } 
01299 }
01300 
01301 ?>

Generated on Fri Dec 13 2013 09:06:40 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1