📄 class.wsdl.php
字号:
<?php
class wsdl extends nusoap_base
{
var $wsdl;
var $schemas = array( );
var $currentSchema;
var $message = array( );
var $complexTypes = array( );
var $messages = array( );
var $currentMessage;
var $currentOperation;
var $portTypes = array( );
var $currentPortType;
var $bindings = array( );
var $currentBinding;
var $ports = array( );
var $currentPort;
var $opData = array( );
var $status = "";
var $documentation = false;
var $endpoint = "";
var $import = array( );
var $parser;
var $position = 0;
var $depth = 0;
var $depth_array = array( );
var $proxyhost = "";
var $proxyport = "";
var $proxyusername = "";
var $proxypassword = "";
var $timeout = 0;
var $response_timeout = 30;
function wsdl( $wsdl = "", $proxyhost = false, $proxyport = false, $proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30 )
{
$this->wsdl = $wsdl;
$this->proxyhost = $proxyhost;
$this->proxyport = $proxyport;
$this->proxyusername = $proxyusername;
$this->proxypassword = $proxypassword;
$this->timeout = $timeout;
$this->response_timeout = $response_timeout;
if ( $wsdl != "" )
{
$this->debug( "initial wsdl URL: ".$wsdl );
$this->parsewsdl( $wsdl );
}
$imported_urls = array( );
$imported = 1;
while ( 0 < $imported )
{
$imported = 0;
foreach ( $this->schemas as $ns => $list )
{
foreach ( $list as $xs )
{
$wsdlparts = parse_url( $this->wsdl );
foreach ( $xs->imports as $ns2 => $list2 )
{
$ii = 0;
for ( ; $ii < count( $list2 ); $ii++ )
{
if ( !$list2[$ii]['loaded'] )
{
$this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true;
$url = $list2[$ii]['location'];
if ( $url != "" )
{
$urlparts = parse_url( $url );
if ( !isset( $urlparts['host'] ) )
{
$url = $wsdlparts['scheme']."://".$wsdlparts['host'].substr( $wsdlparts['path'], 0, strrpos( $wsdlparts['path'], "/" ) + 1 ).$urlparts['path'];
}
if ( !in_array( $url, $imported_urls ) )
{
$this->parsewsdl( $url );
$imported++;
$imported_urls[] = $url;
}
}
else
{
$this->debug( "Unexpected scenario: empty URL for unloaded import" );
}
}
}
}
}
}
$wsdlparts = parse_url( $this->wsdl );
foreach ( $this->import as $ns => $list )
{
$ii = 0;
for ( ; $ii < count( $list ); $ii++ )
{
if ( !$list[$ii]['loaded'] )
{
$this->import[$ns][$ii]['loaded'] = true;
$url = $list[$ii]['location'];
if ( $url != "" )
{
$urlparts = parse_url( $url );
if ( !isset( $urlparts['host'] ) )
{
$url = $wsdlparts['scheme']."://".$wsdlparts['host'].substr( $wsdlparts['path'], 0, strrpos( $wsdlparts['path'], "/" ) + 1 ).$urlparts['path'];
}
if ( !in_array( $url, $imported_urls ) )
{
$this->parsewsdl( $url );
$imported++;
$imported_urls[] = $url;
}
}
else
{
$this->debug( "Unexpected scenario: empty URL for unloaded import" );
}
}
}
}
}
foreach ( $this->bindings as $binding => $bindingData )
{
if ( isset( $bindingData['operations'] ) && is_array( $bindingData['operations'] ) )
{
foreach ( $bindingData['operations'] as $operation => $data )
{
$this->debug( "post-parse data gathering for ".$operation );
$this->bindings[$binding]['operations'][$operation]['input'] = isset( $this->bindings[$binding]['operations'][$operation]['input'] ) ? array_merge( $this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[$bindingData['portType']][$operation]['input'] ) : $this->portTypes[$bindingData['portType']][$operation]['input'];
$this->bindings[$binding]['operations'][$operation]['output'] = isset( $this->bindings[$binding]['operations'][$operation]['output'] ) ? array_merge( $this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[$bindingData['portType']][$operation]['output'] ) : $this->portTypes[$bindingData['portType']][$operation]['output'];
if ( isset( $this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']] ) )
{
$this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']];
}
if ( isset( $this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']] ) )
{
$this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']];
}
if ( isset( $bindingData['style'] ) )
{
$this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style'];
}
$this->bindings[$binding]['operations'][$operation]['transport'] = isset( $bindingData['transport'] ) ? $bindingData['transport'] : "";
$this->bindings[$binding]['operations'][$operation]['documentation'] = isset( $this->portTypes[$bindingData['portType']][$operation]['documentation'] ) ? $this->portTypes[$bindingData['portType']][$operation]['documentation'] : "";
$this->bindings[$binding]['operations'][$operation]['endpoint'] = isset( $bindingData['endpoint'] ) ? $bindingData['endpoint'] : "";
}
}
}
}
function parsewsdl( $wsdl = "" )
{
if ( $wsdl == "" )
{
$this->debug( "no wsdl passed to parseWSDL()!!" );
$this->seterror( "no wsdl passed to parseWSDL()!!" );
return false;
}
$wsdl_props = parse_url( $wsdl );
if ( isset( $wsdl_props['scheme'] ) && ( $wsdl_props['scheme'] == "http" || $wsdl_props['scheme'] == "https" ) )
{
$this->debug( "getting WSDL http(s) URL ".$wsdl );
$tr = new soap_transport_http( $wsdl );
$tr->request_method = "GET";
$tr->useSOAPAction = false;
if ( $this->proxyhost && $this->proxyport )
{
$tr->setproxy( $this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword );
}
if ( isset( $wsdl_props['user'] ) )
{
$tr->setcredentials( $wsdl_props['user'], $wsdl_props['pass'] );
}
$wsdl_string = $tr->send( "", $this->timeout, $this->response_timeout );
$this->debug( "transport debug data...\n".$tr->debug_str );
if ( $err = $tr->geterror( ) )
{
$errstr = "HTTP ERROR: ".$err;
$this->debug( $errstr );
$this->seterror( $errstr );
unset( $tr );
return false;
}
unset( $tr );
}
else
{
if ( isset( $wsdl_props['scheme'] ) && $wsdl_props['scheme'] == "file" && isset( $wsdl_props['path'] ) )
{
$path = isset( $wsdl_props['host'] ) ? $wsdl_props['host'].":".$wsdl_props['path'] : $wsdl_props['path'];
}
else
{
$path = $wsdl;
}
$this->debug( "getting WSDL file ".$path );
if ( $fp = @fopen( $path, "r" ) )
{
$wsdl_string = "";
while ( $data = fread( $fp, 32768 ) )
{
$wsdl_string .= $data;
}
fclose( $fp );
}
else
{
$errstr = "Bad path to WSDL file {$path}";
$this->debug( $errstr );
$this->seterror( $errstr );
return false;
}
}
$this->parser = xml_parser_create( );
xml_parser_set_option( $this->parser, XML_OPTION_CASE_FOLDING, 0 );
xml_set_object( $this->parser, $this );
xml_set_element_handler( $this->parser, "start_element", "end_element" );
xml_set_character_data_handler( $this->parser, "character_data" );
if ( !xml_parse( $this->parser, $wsdl_string, true ) )
{
$errstr = sprintf( "XML error parsing WSDL from %s on line %d: %s", $wsdl, xml_get_current_line_number( $this->parser ), xml_error_string( xml_get_error_code( $this->parser ) ) );
$this->debug( $errstr );
$this->debug( "XML payload:\n".$wsdl_string );
$this->seterror( $errstr );
return false;
}
xml_parser_free( $this->parser );
if ( $this->geterror( ) )
{
return false;
}
return true;
}
function start_element( $parser, $name, $attrs )
{
if ( $this->status == "schema" )
{
$this->currentSchema->schemastartelement( $parser, $name, $attrs );
$this->debug_str .= $this->currentSchema->debug_str;
$this->currentSchema->debug_str = "";
}
else if ( ereg( "schema\$", $name ) )
{
$this->status = "schema";
$this->currentSchema = new xmlschema( "", "", $this->namespaces );
$this->currentSchema->schemastartelement( $parser, $name, $attrs );
$this->debug_str .= $this->currentSchema->debug_str;
$this->currentSchema->debug_str = "";
}
else
{
$pos = $this->position++;
$depth = $this->depth++;
$this->depth_array[$depth] = $pos;
$this->message[$pos] = array( "cdata" => "" );
if ( ereg( ":", $name ) )
{
$prefix = substr( $name, 0, strpos( $name, ":" ) );
$namespace = isset( $this->namespaces[$prefix] ) ? $this->namespaces[$prefix] : "";
$name = substr( strstr( $name, ":" ), 1 );
}
if ( 0 < count( $attrs ) )
{
foreach ( $attrs as $k => $v )
{
if ( ereg( "^xmlns", $k ) )
{
if ( $ns_prefix = substr( strrchr( $k, ":" ), 1 ) )
{
$this->namespaces[$ns_prefix] = $v;
}
else
{
$this->namespaces["ns".( count( $this->namespaces ) + 1 )] = $v;
}
if ( $v == "http://www.w3.org/2001/XMLSchema" || $v == "http://www.w3.org/1999/XMLSchema" )
{
$this->XMLSchemaVersion = $v;
$this->namespaces['xsi'] = $v."-instance";
}
}
$k = strpos( $k, ":" ) ? $this->expandqname( $k ) : $k;
if ( $k != "location" && $k != "soapAction" && $k != "namespace" )
{
$v = strpos( $v, ":" ) ? $this->expandqname( $v ) : $v;
}
$eAttrs[$k] = $v;
}
$attrs = $eAttrs;
}
else
{
$attrs = array( );
}
switch ( $this->status )
{
case "message" :
if ( $name == "part" )
{
if ( isset( $attrs['type'] ) )
{
$this->debug( "msg ".$this->currentMessage.": found part {$attrs['name']}: ".implode( ",", $attrs ) );
$this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
}
if ( isset( $attrs['element'] ) )
{
$this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'];
}
}
break;
case "portType" :
switch ( $name )
{
case "operation" :
$this->currentPortOperation = $attrs['name'];
$this->debug( "portType {$this->currentPortType} operation: {$this->currentPortOperation}" );
if ( isset( $attrs['parameterOrder'] ) )
{
$this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder'];
}
break;
case "documentation" :
$this->documentation = true;
break;
default :
$m = isset( $attrs['message'] ) ? $this->getlocalpart( $attrs['message'] ) : "";
$this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m;
break;
}
break;
case "binding" :
switch ( $name )
{
case "binding" :
if ( isset( $attrs['style'] ) )
{
$this->bindings[$this->currentBinding]['prefix'] = $prefix;
}
$this->bindings[$this->currentBinding] = array_merge( $this->bindings[$this->currentBinding], $attrs );
break;
case "header" :
$this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs;
break;
case "operation" :
if ( isset( $attrs['soapAction'] ) )
{
$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
}
if ( isset( $attrs['style'] ) )
{
$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style'];
}
if ( isset( $attrs['name'] ) )
{
$this->currentOperation = $attrs['name'];
$this->debug( "current binding operation: {$this->currentOperation}" );
$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name'];
$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding;
$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset( $this->bindings[$this->currentBinding]['endpoint'] ) ? $this->bindings[$this->currentBinding]['endpoint'] : "";
}
break;
case "input" :
$this->opStatus = "input";
break;
case "output" :
$this->opStatus = "output";
break;
case "body" :
if ( isset( $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] ) )
{
$this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge( $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs );
}
else
{
$this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
}
break;
}
break;
case "service" :
switch ( $name )
{
case "port" :
$this->currentPort = $attrs['name'];
$this->debug( "current port: ".$this->currentPort );
$this->ports[$this->currentPort]['binding'] = $this->getlocalpart( $attrs['binding'] );
break;
case "address" :
$this->ports[$this->currentPort]['location'] = $attrs['location'];
$this->ports[$this->currentPort]['bindingType'] = $namespace;
$this->bindings[$this->ports[$this->currentPort]['binding']]['bindingType'] = $namespace;
$this->bindings[$this->ports[$this->currentPort]['binding']]['endpoint'] = $attrs['location'];
break;
}
break;
}
switch ( $name )
{
case "import" :
if ( isset( $attrs['location'] ) )
{
$this->import[$attrs['namespace']][] = array(
"location" => $attrs['location'],
"loaded" => false
);
$this->debug( "parsing import ".$attrs['namespace']." - ".$attrs['location']." (".count( $this->import[$attrs['namespace']] ).")" );
}
else
{
$this->import[$attrs['namespace']][] = array(
"location" => "",
"loaded" => true
);
if ( !$this->getprefixfromnamespace( $attrs['namespace'] ) )
{
$this->namespaces["ns".( count( $this->namespaces ) + 1 )] = $attrs['namespace'];
}
$this->debug( "parsing import ".$attrs['namespace']." - [no location] (".count( $this->import[$attrs['namespace']] ).")" );
}
break;
case "message" :
$this->status = "message";
$this->messages[$attrs['name']] = array( );
$this->currentMessage = $attrs['name'];
break;
case "portType" :
$this->status = "portType";
$this->portTypes[$attrs['name']] = array( );
$this->currentPortType = $attrs['name'];
break;
case "binding" :
if ( isset( $attrs['name'] ) )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -