📄 nusoap.php
字号:
<?php
class nusoap_base
{
var $title = "NuSOAP";
var $version = "0.6.7";
var $revision = "\$Revision: 1.72 \$";
var $error_str = false;
var $debug_str = "";
var $charencoding = true;
var $XMLSchemaVersion = "http://www.w3.org/2001/XMLSchema";
var $soap_defencoding = "gb2312";
var $namespaces = array
(
"SOAP-ENV" => "http://schemas.xmlsoap.org/soap/envelope/",
"xsd" => "http://www.w3.org/2001/XMLSchema",
"xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"SOAP-ENC" => "http://schemas.xmlsoap.org/soap/encoding/",
"si" => "http://soapinterop.org/xsd"
);
var $usedNamespaces = array( );
var $typemap = array
(
"http://www.w3.org/2001/XMLSchema" => array
(
"string" => "string",
"boolean" => "boolean",
"float" => "double",
"double" => "double",
"decimal" => "double",
"duration" => "",
"dateTime" => "string",
"time" => "string",
"date" => "string",
"gYearMonth" => "",
"gYear" => "",
"gMonthDay" => "",
"gDay" => "",
"gMonth" => "",
"hexBinary" => "string",
"base64Binary" => "string",
"normalizedString" => "string",
"token" => "string",
"language" => "",
"NMTOKEN" => "",
"NMTOKENS" => "",
"Name" => "",
"NCName" => "",
"ID" => "",
"IDREF" => "",
"IDREFS" => "",
"ENTITY" => "",
"ENTITIES" => "",
"integer" => "integer",
"nonPositiveInteger" => "integer",
"negativeInteger" => "integer",
"long" => "integer",
"int" => "integer",
"short" => "integer",
"byte" => "integer",
"nonNegativeInteger" => "integer",
"unsignedLong" => "",
"unsignedInt" => "",
"unsignedShort" => "",
"unsignedByte" => "",
"positiveInteger" => ""
),
"http://www.w3.org/1999/XMLSchema" => array
(
"i4" => "",
"int" => "integer",
"boolean" => "boolean",
"string" => "string",
"double" => "double",
"float" => "double",
"dateTime" => "string",
"timeInstant" => "string",
"base64Binary" => "string",
"base64" => "string",
"ur-type" => "array"
),
"http://soapinterop.org/xsd" => array
(
"SOAPStruct" => "struct"
),
"http://schemas.xmlsoap.org/soap/encoding/" => array
(
"base64" => "string",
"array" => "array",
"Array" => "array"
),
"http://xml.apache.org/xml-soap" => array
(
0 => "Map"
)
);
var $xmlEntities = array
(
"quot" => "\"",
"amp" => "&",
"lt" => "<",
"gt" => ">",
"apos" => "'"
);
function debug( $string )
{
$this->debug_str .= get_class( $this ).": {$string}\n";
}
function expandentities( $val )
{
if ( $this->charencoding )
{
$val = str_replace( "&", "&", $val );
$val = str_replace( "'", "'", $val );
$val = str_replace( "\"", """, $val );
$val = str_replace( "<", "<", $val );
$val = str_replace( ">", ">", $val );
}
return $val;
}
function geterror( )
{
if ( $this->error_str != "" )
{
return $this->error_str;
}
return false;
}
function seterror( $str )
{
$this->error_str = $str;
}
function isarraysimpleorstruct( $val )
{
$keyList = array_keys( $val );
foreach ( $keyList as $keyListValue )
{
if ( !is_int( $keyListValue ) )
{
return "arrayStruct";
}
}
return "arraySimple";
}
function serialize_val( $val, $name = false, $type = false, $name_ns = false, $type_ns = false, $attributes = false, $use = "encoded" )
{
if ( is_object( $val ) && get_class( $val ) == "soapval" )
{
return $val->serialize( $use );
}
$this->debug( "in serialize_val: {$val}, {$name}, {$type}, {$name_ns}, {$type_ns}, {$attributes}, {$use}" );
$name = !$name || is_numeric( $name ) ? "soapVal" : $name;
$xmlns = "";
if ( $name_ns )
{
$prefix = "nu".rand( 1000, 9999 );
$name = $prefix.":".$name;
$xmlns .= " xmlns:{$prefix}=\"{$name_ns}\"";
}
if ( $type_ns != "" && $type_ns == $this->namespaces['xsd'] )
{
$type_prefix = "xsd";
}
else if ( $type_ns )
{
$type_prefix = "ns".rand( 1000, 9999 );
$xmlns .= " xmlns:{$type_prefix}=\"{$type_ns}\"";
}
$atts = "";
if ( $attributes )
{
foreach ( $attributes as $k => $v )
{
$atts .= " {$k}=\"{$v}\"";
}
}
if ( $type != "" && isset( $this->typemap[$this->XMLSchemaVersion][$type] ) )
{
if ( is_bool( $val ) && !$val )
{
$val = 0;
}
else if ( is_string( $val ) )
{
$val = $this->expandentities( $val );
}
if ( $use == "literal" )
{
return "<{$name}{$xmlns}>{$val}</{$name}>";
}
else
{
return "<{$name}{$xmlns} xsi:type=\"xsd:{$type}\">{$val}</{$name}>";
}
}
$xml = "";
switch ( true )
{
case $type == "" && is_null( $val ) :
if ( $use == "literal" )
{
$xml .= "<{$name}{$xmlns}/>";
}
else
{
$xml .= "<{$name}{$xmlns} xsi:nil=\"true\"/>";
}
break;
case is_bool( $val ) || $type == "boolean" :
if ( !$val )
{
$val = 0;
}
if ( $use == "literal" )
{
$xml .= "<{$name}{$xmlns} {$atts}>{$val}</{$name}>";
}
else
{
$xml .= "<{$name}{$xmlns} xsi:type=\"xsd:boolean\"{$atts}>{$val}</{$name}>";
}
break;
case is_int( $val ) || is_long( $val ) || $type == "int" :
if ( $use == "literal" )
{
$xml .= "<{$name}{$xmlns} {$atts}>{$val}</{$name}>";
}
else
{
$xml .= "<{$name}{$xmlns} xsi:type=\"xsd:int\"{$atts}>{$val}</{$name}>";
}
break;
case is_float( $val ) || is_double( $val ) || $type == "float" :
if ( $use == "literal" )
{
$xml .= "<{$name}{$xmlns} {$atts}>{$val}</{$name}>";
}
else
{
$xml .= "<{$name}{$xmlns} xsi:type=\"xsd:float\"{$atts}>{$val}</{$name}>";
}
break;
case is_string( $val ) || $type == "string" :
$val = $this->expandentities( $val );
if ( $use == "literal" )
{
$xml .= "<{$name}{$xmlns} {$atts}>{$val}</{$name}>";
}
else
{
$xml .= "<{$name}{$xmlns} xsi:type=\"xsd:string\"{$atts}>{$val}</{$name}>";
}
break;
case is_object( $val ) :
$name = get_class( $val );
foreach ( get_object_vars( $val ) as $k => $v )
{
$pXml = isset( $pXml ) ? $pXml.$this->serialize_val( $v, $k, false, false, false, false, $use ) : $this->serialize_val( $v, $k, false, false, false, false, $use );
}
$xml .= "<".$name.">".$pXml."</".$name.">";
break;
case is_array( $val ) || $type :
$valueType = $this->isarraysimpleorstruct( $val );
if ( $valueType == "arraySimple" || ereg( "^ArrayOf", $type ) )
{
$i = 0;
if ( is_array( $val ) && 0 < count( $val ) )
{
foreach ( $val as $v )
{
if ( is_object( $v ) && get_class( $v ) == "soapval" )
{
$tt_ns = $v->type_ns;
$tt = $v->type;
}
else
{
$tt = gettype( $v );
}
$array_types[$tt] = 1;
$xml .= $this->serialize_val( $v, "item", false, false, false, false, $use );
++$i;
}
if ( 1 < count( $array_types ) )
{
$array_typename = "xsd:ur-type";
}
else if ( isset( $tt ) && isset( $this->typemap[$this->XMLSchemaVersion][$tt] ) )
{
$array_typename = "xsd:".$tt;
}
else if ( $tt == "array" || $tt == "Array" )
{
$array_typename = "SOAP-ENC:Array";
}
else if ( $tt_ns != "" && $tt_ns == $this->namespaces['xsd'] )
{
$array_typename = "xsd:".$tt;
}
else if ( $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, $type_prefix ) )
{
$type_str = " xsi:type=\"{$type_prefix}:{$type}\"";
}
else
{
$type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[{$array_type}]\"";
}
}
else if ( $use == "literal" )
{
$type_str = "";
}
else if ( isset( $type, $type_prefix ) )
{
$type_str = " xsi:type=\"{$type_prefix}:{$type}\"";
}
else
{
$type_str = " xsi:type=\"SOAP-ENC:Array\"";
}
$xml = "<{$name}{$xmlns}{$type_str}{$atts}>".$xml."</{$name}>";
}
else
{
if ( isset( $type, $type_prefix ) )
{
$type_str = " xsi:type=\"{$type_prefix}:{$type}\"";
}
else
{
$type_str = "";
}
if ( $use == "literal" )
{
$xml .= "<{$name}{$xmlns} {$atts}>";
}
else
{
$xml .= "<{$name}{$xmlns}{$type_str}{$atts}>";
}
foreach ( $val as $k => $v )
{
if ( $type == "Map" && $type_ns == "http://xml.apache.org/xml-soap" )
{
$xml .= "<item>";
$xml .= $this->serialize_val( $k, "key", false, false, false, false, $use );
$xml .= $this->serialize_val( $v, "value", false, false, false, false, $use );
$xml .= "</item>";
}
else
{
$xml .= $this->serialize_val( $v, $k, false, false, false, false, $use );
}
}
$xml .= "</{$name}>";
break;
}
default :
$xml .= "not detected, got ".gettype( $val )." for ".$val;
break;
}
return $xml;
}
function serializeenvelope( $body, $headers = false, $namespaces = array( ), $style = "rpc", $use = "encoded" )
{
$ns_string = "";
foreach ( array_merge( $this->namespaces, $namespaces ) as $k => $v )
{
$ns_string .= " xmlns:{$k}=\"{$v}\"";
}
if ( $style == "rpc" && $use == "encoded" )
{
$ns_string = " SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"".$ns_string;
}
if ( $headers )
{
$headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>";
}
return "<?xml version=\"1.0\" encoding=\"".$this->soap_defencoding."\"?".">"."<SOAP-ENV:Envelope".$ns_string.">".$headers."<SOAP-ENV:Body>".$body."</SOAP-ENV:Body>"."</SOAP-ENV:Envelope>";
}
function formatdump( $str )
{
$str = htmlspecialchars( $str );
return nl2br( $str );
}
function contractqname( $qname )
{
if ( strrpos( $qname, ":" ) )
{
$name = substr( $qname, strrpos( $qname, ":" ) + 1 );
$ns = substr( $qname, 0, strrpos( $qname, ":" ) );
$p = $this->getprefixfromnamespace( $ns );
if ( $p )
{
return $p.":".$name;
}
return $qname;
}
else
{
return $qname;
}
}
function expandqname( $qname )
{
if ( strpos( $qname, ":" ) && !ereg( "^http://", $qname ) )
{
$name = substr( strstr( $qname, ":" ), 1 );
$prefix = substr( $qname, 0, strpos( $qname, ":" ) );
if ( isset( $this->namespaces[$prefix] ) )
{
return $this->namespaces[$prefix].":".$name;
}
else
{
return $qname;
}
}
else
{
return $qname;
}
}
function getlocalpart( $str )
{
if ( $sstr = strrchr( $str, ":" ) )
{
return substr( $sstr, 1 );
}
else
{
return $str;
}
}
function getprefix( $str )
{
if ( $pos = strrpos( $str, ":" ) )
{
return substr( $str, 0, $pos );
}
return false;
}
function getnamespacefromprefix( $prefix )
{
if ( isset( $this->namespaces[$prefix] ) )
{
return $this->namespaces[$prefix];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -