@ -9,7 +9,7 @@
*
* @author Dietrich Ayala < dietrich @ ganx4 . com >
* @author Scott Nichol < snichol @ users . sourceforge . net >
* @version $Id: class.wsdl.php,v 1.69 2007/11/06 15:17:46 snichol Exp $
* @version $Id: class.wsdl.php,v 1.76 2010/04/26 20:15:08 snichol Exp $
* @access public
*/
class wsdl extends nusoap_base {
@ -223,7 +223,7 @@ class wsdl extends nusoap_base {
$this->appendDebug($tr->getDebug());
// catch errors
if($err = $tr->getError() ){
$errstr = 'HTTP ERROR: '.$err;
$errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: '.$err;
$this->debug($errstr);
$this->setError($errstr);
unset($tr);
@ -302,7 +302,7 @@ class wsdl extends nusoap_base {
$this->currentSchema->schemaStartElement($parser, $name, $attrs);
$this->appendDebug($this->currentSchema->getDebug());
$this->currentSchema->clearDebug();
} elseif (ereg('schema$ ', $name)) {
} elseif (preg_match('/schema$/ ', $name)) {
$this->debug('Parsing WSDL schema');
// $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")");
$this->status = 'schema';
@ -321,7 +321,7 @@ class wsdl extends nusoap_base {
if (count($attrs) > 0) {
// register namespace declarations
foreach($attrs as $k => $v) {
if (ereg("^xmlns", $k)) {
if (preg_match('/^xmlns/', $k)) {
if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
$this->namespaces[$ns_prefix] = $v;
} else {
@ -346,7 +346,7 @@ class wsdl extends nusoap_base {
$attrs = array();
}
// get element prefix, namespace and name
if (ereg(': ', $name)) {
if (preg_match('/:/ ', $name)) {
// get ns prefix
$prefix = substr($name, 0, strpos($name, ':'));
// get ns
@ -511,7 +511,7 @@ class wsdl extends nusoap_base {
*/
function end_element($parser, $name){
// unset schema status
if (/*ereg('types$', $name) ||*/ ereg('schema$ ', $name)) {
if (/*preg_match('/types$/', $name) ||*/ preg_match('/schema$/ ', $name)) {
$this->status = "";
$this->appendDebug($this->currentSchema->getDebug());
$this->currentSchema->clearDebug();
@ -578,30 +578,40 @@ class wsdl extends nusoap_base {
/**
* returns an assoc array of operation names => operation data
*
* @param string $portName WSDL port name
* @param string $bindingType eg: soap, smtp, dime (only soap and soap12 are currently supported)
* @return array
* @access public
*/
function getOperations($bindingType = 'soap') {
function getOperations($portName = '', $ bindingType = 'soap') {
$ops = array();
if ($bindingType == 'soap') {
$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
} elseif ($bindingType == 'soap12') {
$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
} else {
$this->debug("getOperations bindingType $bindingType may not be supported");
}
$this->debug("getOperations for port '$portName' bindingType $bindingType");
// loop thru ports
foreach($this->ports as $port => $portData) {
// binding type of port matches parameter
if ($portData['bindingType'] == $bindingType) {
//$this->debug("getOperations for port $port");
//$this->debug("port data: " . $this->varDump($portData));
//$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ]));
// merge bindings
if (isset($this->bindings[ $portData['binding'] ]['operations'])) {
$ops = array_merge ($ops, $this->bindings[ $portData['binding'] ]['operations']);
$this->debug("getOperations checking port $port bindingType " . $portData['bindingType']);
if ($portName == '' || $port == $portName) {
// binding type of port matches parameter
if ($portData['bindingType'] == $bindingType) {
$this->debug("getOperations found port $port bindingType $bindingType");
//$this->debug("port data: " . $this->varDump($portData));
//$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ]));
// merge bindings
if (isset($this->bindings[ $portData['binding'] ]['operations'])) {
$ops = array_merge ($ops, $this->bindings[ $portData['binding'] ]['operations']);
}
}
}
}
if (count($ops) == 0) {
$this->debug("getOperations found no operations for port '$portName' bindingType $bindingType");
}
return $ops;
}
@ -703,9 +713,10 @@ class wsdl extends nusoap_base {
for ($i = 0; $i < count ( $ this- > schemas[$ns]); $i++) {
$xs = &$this->schemas[$ns][$i];
$t = $xs->getTypeDef($type);
// $this->appendDebug($xs->getDebug());
// $xs->clearDebug();
$this->appendDebug($xs->getDebug());
$xs->clearDebug();
if ($t) {
$this->debug("in getTypeDef: found type $type");
if (!isset($t['phpType'])) {
// get info for type to tack onto the element
$uqType = substr($t['type'], strrpos($t['type'], ':') + 1);
@ -723,11 +734,14 @@ class wsdl extends nusoap_base {
if (isset($etype['attrs'])) {
$t['attrs'] = $etype['attrs'];
}
} else {
$this->debug("did not find type for [element] $type");
}
}
return $t;
}
}
$this->debug("in getTypeDef: did not find type $type");
} else {
$this->debug("in getTypeDef: do not have schema for namespace $ns");
}
@ -766,8 +780,9 @@ class wsdl extends nusoap_base {
background-color: #ccccff; width: 20%; margin-left: 20px; margin-top: 20px; }
.title {
font-family: arial; font-size: 26px; color: #ffffff;
background-color: #999999; width: 105%; margin-left: 0px;
padding-top: 10px; padding-bottom: 10px; padding-left: 15px;}
background-color: #999999; width: 100%;
margin-left: 0px; margin-right: 0px;
padding-top: 10px; padding-bottom: 10px;}
.hidden {
position: absolute; visibility: hidden; z-index: 200; left: 250px; top: 100px;
font-family: arial; overflow: hidden; width: 600;
@ -1056,18 +1071,8 @@ class wsdl extends nusoap_base {
if (isset($typeDef['elements']) & & is_array($typeDef['elements'])) {
$elements = 0;
$matches = 0;
$change = false;
if ($this->isArraySimpleOrStruct($parameters) == 'arraySimple' & & count($parameters) == count($typeDef['elements'])) {
$this->debug("in parametersMatchWrapped: (wrapped return value kludge) correct number of elements in simple array, so change array and wrap");
$change = true;
}
foreach ($typeDef['elements'] as $name => $attrs) {
if ($change) {
$this->debug("in parametersMatchWrapped: change parameter $element to name $name");
$parameters[$name] = $parameters[$elements];
unset($parameters[$elements]);
$matches++;
} elseif (isset($parameters[$name])) {
if (isset($parameters[$name])) {
$this->debug("in parametersMatchWrapped: have parameter named $name");
$matches++;
} else {
@ -1143,7 +1148,14 @@ class wsdl extends nusoap_base {
// check for Microsoft-style wrapped parameters
if ($style == 'document' & & $use == 'literal' & & $part_count == 1 & & isset($parts['parameters'])) {
$this->debug('check whether the caller has wrapped the parameters');
if ((($parametersArrayType == 'arrayStruct' || $parameter_count == 0) & & !isset($parameters['parameters'])) || ($direction == 'output' & & $parametersArrayType == 'arraySimple' & & $parameter_count == 1)) {
if ($direction == 'output' & & $parametersArrayType == 'arraySimple' & & $parameter_count == 1) {
// TODO: consider checking here for double-wrapping, when
// service function wraps, then NuSOAP wraps again
$this->debug("change simple array to associative with 'parameters' element");
$parameters['parameters'] = $parameters[0];
unset($parameters[0]);
}
if (($parametersArrayType == 'arrayStruct' || $parameter_count == 0) & & !isset($parameters['parameters'])) {
$this->debug('check whether caller\'s parameters match the wrapped ones');
if ($this->parametersMatchWrapped($parts['parameters'], $parameters)) {
$this->debug('wrap the parameters for the caller');
@ -1428,6 +1440,11 @@ class wsdl extends nusoap_base {
$uqType = substr($uqType, 0, -1);
}
}
if (!isset($typeDef['phpType'])) {
$this->setError("$type ($uqType) has no phpType.");
$this->debug("in serializeType: $type ($uqType) has no phpType.");
return false;
}
$phpType = $typeDef['phpType'];
$this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '') );
// if php type == struct, map value to the < all > element names
@ -1449,7 +1466,7 @@ class wsdl extends nusoap_base {
}
if (is_null($value)) {
if ($use == 'literal') {
// TODO: depends on minOccurs
// TODO: depends on minOccurs and nillable
$xml = "< $elementName$elementNS/>";
} else {
$xml = "< $elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
@ -1472,7 +1489,17 @@ class wsdl extends nusoap_base {
$xml = "< $elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>";
}
$xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
if (isset($typeDef['simpleContent']) & & $typeDef['simpleContent'] == 'true') {
if (isset($value['!'])) {
$xml .= $value['!'];
$this->debug("in serializeType: serialized simpleContent for type $type");
} else {
$this->debug("in serializeType: no simpleContent to serialize for type $type");
}
} else {
// complexContent
$xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
}
$xml .= "< /$elementName>";
} else {
$this->debug("in serializeType: phpType is struct, but value is not an array");
@ -1582,7 +1609,21 @@ class wsdl extends nusoap_base {
* @access private
*/
function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType) {
$this->debug("serializeComplexTypeAttributes for XML Schema type $ns:$uqType");
$xml = '';
if (isset($typeDef['extensionBase'])) {
$nsx = $this->getPrefix($typeDef['extensionBase']);
$uqTypex = $this->getLocalPart($typeDef['extensionBase']);
if ($this->getNamespaceFromPrefix($nsx)) {
$nsx = $this->getNamespaceFromPrefix($nsx);
}
if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) {
$this->debug("serialize attributes for extension base $nsx:$uqTypex");
$xml .= $this->serializeComplexTypeAttributes($typeDefx, $value, $nsx, $uqTypex);
} else {
$this->debug("extension base $nsx:$uqTypex is not a supported type");
}
}
if (isset($typeDef['attrs']) & & is_array($typeDef['attrs'])) {
$this->debug("serialize attributes for XML Schema type $ns:$uqType");
if (is_array($value)) {
@ -1615,19 +1656,6 @@ class wsdl extends nusoap_base {
} else {
$this->debug("no attributes to serialize for XML Schema type $ns:$uqType");
}
if (isset($typeDef['extensionBase'])) {
$ns = $this->getPrefix($typeDef['extensionBase']);
$uqType = $this->getLocalPart($typeDef['extensionBase']);
if ($this->getNamespaceFromPrefix($ns)) {
$ns = $this->getNamespaceFromPrefix($ns);
}
if ($typeDef = $this->getTypeDef($uqType, $ns)) {
$this->debug("serialize attributes for extension base $ns:$uqType");
$xml .= $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType);
} else {
$this->debug("extension base $ns:$uqType is not a supported type");
}
}
return $xml;
}
@ -1644,7 +1672,21 @@ class wsdl extends nusoap_base {
* @access private
*/
function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use='encoded', $encodingStyle=false) {
$this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType");
$xml = '';
if (isset($typeDef['extensionBase'])) {
$nsx = $this->getPrefix($typeDef['extensionBase']);
$uqTypex = $this->getLocalPart($typeDef['extensionBase']);
if ($this->getNamespaceFromPrefix($nsx)) {
$nsx = $this->getNamespaceFromPrefix($nsx);
}
if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) {
$this->debug("serialize elements for extension base $nsx:$uqTypex");
$xml .= $this->serializeComplexTypeElements($typeDefx, $value, $nsx, $uqTypex, $use, $encodingStyle);
} else {
$this->debug("extension base $nsx:$uqTypex is not a supported type");
}
}
if (isset($typeDef['elements']) & & is_array($typeDef['elements'])) {
$this->debug("in serializeComplexTypeElements, serialize elements for XML Schema type $ns:$uqType");
if (is_array($value)) {
@ -1701,7 +1743,12 @@ class wsdl extends nusoap_base {
}
}
} else {
if (isset($attrs['type']) || isset($attrs['ref'])) {
if (is_null($v) & & isset($attrs['minOccurs']) & & $attrs['minOccurs'] == '0') {
// do nothing
} elseif (is_null($v) & & isset($attrs['nillable']) & & $attrs['nillable'] == 'true') {
// TODO: serialize a nil correctly, but for now serialize schema-defined type
$xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
} elseif (isset($attrs['type']) || isset($attrs['ref'])) {
// serialize schema-defined type
$xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
} else {
@ -1715,19 +1762,6 @@ class wsdl extends nusoap_base {
} else {
$this->debug("no elements to serialize for XML Schema type $ns:$uqType");
}
if (isset($typeDef['extensionBase'])) {
$ns = $this->getPrefix($typeDef['extensionBase']);
$uqType = $this->getLocalPart($typeDef['extensionBase']);
if ($this->getNamespaceFromPrefix($ns)) {
$ns = $this->getNamespaceFromPrefix($ns);
}
if ($typeDef = $this->getTypeDef($uqType, $ns)) {
$this->debug("serialize elements for extension base $ns:$uqType");
$xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
} else {
$this->debug("extension base $ns:$uqType is not a supported type");
}
}
return $xml;
}
@ -1833,7 +1867,7 @@ class wsdl extends nusoap_base {
if ($style == 'document') {
$elements = array();
foreach ($in as $n => $t) {
$elements[$n] = array('name' => $n, 'type' => $t);
$elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified' );
}
$this->addComplexType($name . 'RequestType', 'complexType', 'struct', 'all', '', $elements);
$this->addElement(array('name' => $name, 'type' => $name . 'RequestType'));
@ -1841,7 +1875,7 @@ class wsdl extends nusoap_base {
$elements = array();
foreach ($out as $n => $t) {
$elements[$n] = array('name' => $n, 'type' => $t);
$elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified' );
}
$this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements);
$this->addElement(array('name' => $name . 'Response', 'type' => $name . 'ResponseType', 'form' => 'qualified'));