<?php
/*
* SOAP Client Helper
* Created: Apr 18, 2007
* License: LGPL (open source)
* BungeeLabs, Inc.
*
* Dependency: NuSOAP at http://dietrich.ganx4.com/nusoap
*/
/**
*
* This is a helper function taken DIRECTLY from NuSOAP.php except that
* it serializes an array *without* wrapping in an element.
* NOTE: Needed only when using soapclient calls.
* Generally only needs the $val parameter to be set for RPC style.
*
* @param mixed $val The value to serialize
* @param string $name The name (local part) of the XML element
* @param string $type The XML schema type (local part) for the element
* @param string $type_ns The namespace for the type of the element
* @param string $use The WSDL "use" (encoded|literal)
* @return string The serialized element, possibly with child elements
*/
function serializeArray($val, $type=false, $type_ns=false, $use='encoded') {
$xml = '';
$sv = new soapval();
$valueType = $sv->isArraySimpleOrStruct($val);
if($valueType=='arraySimple'){
$i = 0;
if(is_array($val) && count($val)> 0){
foreach($val as $v){
if(is_object($v) && get_class($v) == 'soapval'){
$tt_ns = $v->type_ns;
$tt = $v->type;
} elseif (is_array($v)) {
$tt = $sv->isArraySimpleOrStruct($v);
} else {
$tt = gettype($v);
}
$array_types[$tt] = 1;
$xml .= $sv->serialize_val($v,'item',false,false,false,false,$use);
++$i;
}
if(count($array_types) > 1){
$array_typename = 'xsd:anyType';
} elseif(isset($tt) && isset($sv->typemap[$sv->XMLSchemaVersion][$tt])) {
if ($tt == 'integer') {
$tt = 'int';
}
$array_typename = 'xsd:'.$tt;
} elseif(isset($tt) && $tt == 'arraySimple'){
$array_typename = 'SOAP-ENC:Array';
} elseif(isset($tt) && $tt == 'arrayStruct'){
$array_typename = 'unnamed_struct_use_soapval';
} else {
// if type is prefixed, create type prefix
if ($tt_ns != '' && $tt_ns == $sv->namespaces['xsd']){
$array_typename = 'xsd:' . $tt;
} elseif ($tt_ns) {
$tt_prefix = 'ns' . rand(1000, 9999);
$array_typename = "$tt_prefix:$tt";
$xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
} else {
$array_typename = $tt;
}
}
$array_type = $i;
if ($use == 'literal') {
$type_str = '';
} else if (isset($type) && isset($type_prefix)) {
$type_str = " xsi:type=\"$type_prefix:$type\"";
} else {
$type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\"";
}
// empty array
} else {
if ($use == 'literal') {
$type_str = '';
} else if (isset($type) && isset($type_prefix)) {
$type_str = " xsi:type=\"$type_prefix:$type\"";
} else {
$type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\"";
}
}
} else {
// got a struct
if(isset($type) && isset($type_prefix)){
$type_str = " xsi:type=\"$type_prefix:$type\"";
} else {
$type_str = '';
}
foreach($val as $k => $v){
// Apache Map
if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') {
$xml .= '<item>';
$xml .= $sv->serialize_val($k,'key',false,false,false,false,$use);
$xml .= $sv->serialize_val($v,'value',false,false,false,false,$use);
$xml .= '</item>';
} else {
$xml .= $sv->serialize_val($v,$k,false,false,false,false,$use);
}
}
}
return $xml;
}
?>