format, add headers

This commit is contained in:
Miles Lott 2001-10-17 22:08:38 +00:00
parent e7534433bc
commit 6d40e78fe9

View File

@ -1,18 +1,30 @@
<?php <?php
/* /*
SOAPx4
by Dietrich Ayala (C) 2001 dietrich@ganx4.com
This project began based on code from the 2 projects below,
and still contains some original code. The licenses of both must be respected.
XML-RPC for PHP
originally by Edd Dumbill (C) 1999-2000
SOAP for PHP
by Victor Zou (C) 2000-2001 <victor@gigaideas.com.cn>
this is a class that loads a wsdl file and makes it's data available to an application this is a class that loads a wsdl file and makes it's data available to an application
it should provide methods that allow both client and server usage of it it should provide methods that allow both client and server usage of it
also should have methods for creating a wsdl file from scratch and also should have methods for creating a wsdl file from scratch and
serializing wsdl into valid markup serializing wsdl into valid markup
*/ */
/* $Id$ */
class wsdl class wsdl
{ {
// constructor // constructor
function wsdl($wsdl=false) function wsdl($wsdl=False)
{ {
// define internal arrays of bindings, ports, operations, messages, etc. // define internal arrays of bindings, ports, operations, messages, etc.
$this->complexTypes = array(); $this->complexTypes = array();
@ -25,7 +37,7 @@ class wsdl
$this->bindings = array(); $this->bindings = array();
$this->currentBinding; $this->currentBinding;
// debug switch // debug switch
$this->debug_flag = false; $this->debug_flag = False;
// parser vars // parser vars
$this->parser; $this->parser;
$this->position; $this->position;
@ -34,7 +46,7 @@ class wsdl
if($wsdl == "-1") if($wsdl == "-1")
{ {
$wsdl=false; $wsdl=False;
} }
// Check whether content has been read. // Check whether content has been read.
if($wsdl) if($wsdl)
@ -48,18 +60,18 @@ class wsdl
// Set the object for the parser. // Set the object for the parser.
xml_set_object($this->parser, &$this); xml_set_object($this->parser, &$this);
// Set the element handlers for the parser. // Set the element handlers for the parser.
xml_set_element_handler($this->parser, "start_element","end_element"); xml_set_element_handler($this->parser, 'start_element','end_element');
xml_set_character_data_handler($this->parser,"character_data"); xml_set_character_data_handler($this->parser,'character_data');
//xml_set_default_handler($this->parser, "default_handler"); //xml_set_default_handler($this->parser, 'default_handler');
// Parse the XML file. // Parse the XML file.
if(!xml_parse($this->parser,$wsdl_string,true)) if(!xml_parse($this->parser,$wsdl_string,True))
{ {
// Display an error message. // Display an error message.
$this->debug(sprintf("XML error on line %d: %s", $this->debug(sprintf('XML error on line %d: %s',
xml_get_current_line_number($this->parser), xml_get_current_line_number($this->parser),
xml_error_string(xml_get_error_code($this->parser)))); xml_error_string(xml_get_error_code($this->parser))));
$this->fault = true; $this->fault = True;
} }
xml_parser_free($this->parser); xml_parser_free($this->parser);
} }
@ -77,90 +89,92 @@ class wsdl
// find status, register data // find status, register data
switch($this->status) switch($this->status)
{ {
case "types": case 'types':
switch($name) switch($name)
{ {
case "schema": case 'schema':
$this->schema = true; $this->schema = True;
break; break;
case "complexType": case 'complexType':
$this->currentElement = $attrs["name"]; $this->currentElement = $attrs['name'];
$this->schemaStatus = "complexType"; $this->schemaStatus = 'complexType';
break; break;
case "element": case 'element':
$this->complexTypes[$this->currentElement]["elements"][$attrs["name"]] = $attrs; $this->complexTypes[$this->currentElement]['elements'][$attrs['name']] = $attrs;
break; break;
case "complexContent": case 'complexContent':
break; break;
case "restriction": case 'restriction':
$this->complexTypes[$this->currentElement]["restrictionBase"] = $attrs["base"]; $this->complexTypes[$this->currentElement]['restrictionBase'] = $attrs['base'];
break; break;
case "sequence": case 'sequence':
$this->complexTypes[$this->currentElement]["order"] = "sequence"; $this->complexTypes[$this->currentElement]['order'] = 'sequence';
break; break;
case "all": case "all":
$this->complexTypes[$this->currentElement]["order"] = "all"; $this->complexTypes[$this->currentElement]['order'] = 'all';
break; break;
case "attribute": case 'attribute':
if($attrs["ref"]){ if($attrs['ref'])
$this->complexTypes[$this->currentElement]["attrs"][$attrs["ref"]] = $attrs;
} elseif($attrs["name"]){
$this->complexTypes[$this->currentElement]["attrs"][$attrs["name"]] = $attrs;
}
break;
}
break;
case "message":
if($name == "part")
{ {
$this->messages[$this->currentMessage][$attrs["name"]] = $attrs["type"]; $this->complexTypes[$this->currentElement]['attrs'][$attrs['ref']] = $attrs;
}
elseif($attrs['name'])
{
$this->complexTypes[$this->currentElement]['attrs'][$attrs['name']] = $attrs;
} }
break; break;
case "portType": }
break;
case 'message':
if($name == 'part')
{
$this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
}
break;
case 'portType':
switch($name) switch($name)
{ {
case "operation": case 'operation':
$this->currentOperation = $attrs["name"]; $this->currentOperation = $attrs['name'];
$this->portTypes[$this->currentPortType][$attrs["name"]] = $attrs["parameterOrder"]; $this->portTypes[$this->currentPortType][$attrs['name']] = $attrs['parameterOrder'];
break; break;
default: default:
$this->portOperations[$this->currentOperation][$name]= $attrs; $this->portOperations[$this->currentOperation][$name]= $attrs;
break; break;
} }
break; break;
case "binding": case 'binding':
switch($name) switch($name)
{ {
case "soap:binding": case 'soap:binding':
$this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding],$attrs); $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding],$attrs);
break; break;
case "operation": case 'operation':
$this->currentOperation = $attrs["name"]; $this->currentOperation = $attrs['name'];
$this->bindings[$this->currentBinding]["operations"][$attrs["name"]] = array(); $this->bindings[$this->currentBinding]['operations'][$attrs['name']] = array();
break; break;
case "soap:operation": case 'soap:operation':
$this->bindings[$this->currentBinding]["operations"][$this->currentOperation]["soapAction"] = $attrs["soapAction"]; $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
break; break;
case "input": case 'input':
$this->opStatus = "input"; $this->opStatus = 'input';
case "soap:body": case 'soap:body':
$this->bindings[$this->currentBinding]["operations"][$this->currentOperation][$this->opStatus] = $attrs; $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
break; break;
case "output": case 'output':
$this->opStatus = "output"; $this->opStatus = 'output';
break; break;
} }
break; break;
case "service": case 'service':
switch($name) switch($name)
{ {
case "port": case 'port':
$this->currentPort = $attrs["name"]; $this->currentPort = $attrs['name'];
$this->ports[$attrs["name"]] = $attrs; $this->ports[$attrs['name']] = $attrs;
break; break;
case "soap:address": case 'soap:address':
$this->ports[$this->currentPort]["location"] = $attrs["location"]; $this->ports[$this->currentPort]['location'] = $attrs['location'];
break; break;
} }
break; break;
@ -168,42 +182,42 @@ class wsdl
// set status // set status
switch($name) switch($name)
{ {
case "types": case 'types':
$this->status = "types"; $this->status = 'types';
break; break;
case "message": case 'message':
$this->status = "message"; $this->status = 'message';
$this->messages[$attrs["name"]] = array(); $this->messages[$attrs['name']] = array();
$this->currentMessage = $attrs["name"]; $this->currentMessage = $attrs['name'];
break; break;
case "portType": case 'portType':
$this->status = "portType"; $this->status = 'portType';
$this->portTypes[$attrs["name"]] = array(); $this->portTypes[$attrs['name']] = array();
$this->currentPortType = $attrs["name"]; $this->currentPortType = $attrs['name'];
break; break;
case "binding": case 'binding':
$this->status = "binding"; $this->status = 'binding';
$this->currentBinding = $attrs["name"]; $this->currentBinding = $attrs['name'];
$this->bindings[$attrs["name"]]["type"] = $attrs["type"]; $this->bindings[$attrs['name']]['type'] = $attrs['type'];
break; break;
case "service": case 'service':
$this->status = "service"; $this->status = 'service';
break; break;
} }
// get element prefix // get element prefix
if(ereg(":",$name)) if(ereg(":",$name))
{ {
$prefix = substr($name,0,strpos($name,":")); $prefix = substr($name,0,strpos($name,':'));
} }
} }
function getEndpoint($portName) function getEndpoint($portName)
{ {
if($endpoint = $this->ports[$portName]["location"]) if($endpoint = $this->ports[$portName]['location'])
{ {
return $endpoint; return $endpoint;
} }
return false; return False;
} }
function getPortName($operation) function getPortName($operation)
@ -212,9 +226,9 @@ class wsdl
while(list($port,$portAttrs) = @each($this->ports)); while(list($port,$portAttrs) = @each($this->ports));
/* foreach($this->ports as $port => $portAttrs) */ /* foreach($this->ports as $port => $portAttrs) */
{ {
$binding = substr($portAttrs["binding"],4); $binding = substr($portAttrs['binding'],4);
@reset($this->bindings[$binding]["operations"]); @reset($this->bindings[$binding]['operations']);
while(list($op,$opAttrs) = @each($this->bindings[$binding]["operations"])) while(list($op,$opAttrs) = @each($this->bindings[$binding]['operations']))
/* foreach($this->bindings[$binding]["operations"] as $op => $opAttrs) */ /* foreach($this->bindings[$binding]["operations"] as $op => $opAttrs) */
{ {
if($op == $operation) if($op == $operation)
@ -227,29 +241,29 @@ class wsdl
function getSoapAction($portName,$operation) function getSoapAction($portName,$operation)
{ {
if($binding = substr($this->ports[$portName]["binding"],4)) if($binding = substr($this->ports[$portName]['binding'],4))
{ {
if($soapAction = $this->bindings[$binding]["operations"][$operation]["soapAction"]) if($soapAction = $this->bindings[$binding]['operations'][$operation]['soapAction'])
{ {
return $soapAction; return $soapAction;
} }
return false; return False;
} }
return false; return False;
} }
function getNamespace($portName,$operation) function getNamespace($portName,$operation)
{ {
if($binding = substr($this->ports[$portName]["binding"],4)) if($binding = substr($this->ports[$portName]['binding'],4))
{ {
//$this->debug("looking for namespace using binding '$binding', port '$portName', operation '$operation'"); //$this->debug("looking for namespace using binding '$binding', port '$portName', operation '$operation'");
if($namespace = $this->bindings[$binding]["operations"][$operation]["input"]["namespace"]) if($namespace = $this->bindings[$binding]['operations'][$operation]['input']['namespace'])
{ {
return $namespace; return $namespace;
} }
return false; return False;
} }
return false; return False;
} }
// end-element handler // end-element handler
@ -265,7 +279,7 @@ class wsdl
function character_data($parser, $data) function character_data($parser, $data)
{ {
$pos = $this->depth_array[$this->depth]; $pos = $this->depth_array[$this->depth];
$this->message[$pos]["cdata"] .= $data; $this->message[$pos]['cdata'] .= $data;
} }
function debug($string) function debug($string)