'.$this->wsdl->serviceName.'
View the WSDL for the service.
Click on an operation name to view it's details.
';
foreach($this->wsdl->getOperations() as $op => $data){
$b .= "- $op
";
// create hidden div
$b .= "
Close";
foreach($data as $donnie => $marie){ // loop through opdata
if($donnie == 'input' || $donnie == 'output'){ // show input/output data
$b .= "
".ucfirst($donnie).':';
foreach($marie as $captain => $tenille){ // loop through data
if($captain == 'parts'){ // loop thru parts
$b .= " $captain:
";
//if(is_array($tenille)){
foreach($tenille as $joanie => $chachi){
$b .= " $joanie: $chachi
";
}
//}
} else {
$b .= " $captain: $tenille
";
}
}
} else {
$b .= "
".ucfirst($donnie).": $marie
";
}
}
$b .= '
';
}
$b .= '
';
return $b;
}
/**
* sets up wsdl object
* this acts as a flag to enable internal WSDL generation
* NOTE: NOT FUNCTIONAL
*
* @param string $serviceName, name of the service
* @param string $namespace, tns namespace
*/
function configureWSDL($serviceName,$namespace = false,$endpoint = false,$style='rpc', $transport = 'http://schemas.xmlsoap.org/soap/http')
{
$SERVER_NAME = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $GLOBALS['SERVER_NAME'];
$SCRIPT_NAME = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : $GLOBALS['SCRIPT_NAME'];
if(false == $namespace) {
$namespace = "http://$SERVER_NAME/soap/$serviceName";
}
if(false == $endpoint) {
$endpoint = "http://$SERVER_NAME$SCRIPT_NAME";
}
$this->wsdl = new wsdl;
$this->wsdl->serviceName = $serviceName;
$this->wsdl->endpoint = $endpoint;
$this->wsdl->namespaces['tns'] = $namespace;
$this->wsdl->namespaces['soap'] = 'http://schemas.xmlsoap.org/wsdl/soap/';
$this->wsdl->namespaces['wsdl'] = 'http://schemas.xmlsoap.org/wsdl/';
$this->wsdl->bindings[$serviceName.'Binding'] = array(
'name'=>$serviceName.'Binding',
'style'=>$style,
'transport'=>$transport,
'portType'=>$serviceName.'PortType');
$this->wsdl->ports[$serviceName.'Port'] = array(
'binding'=>$serviceName.'Binding',
'location'=>$endpoint,
'bindingType'=>'http://schemas.xmlsoap.org/wsdl/soap/');
}
}
?>
* @version v 0.6.3
* @access public
*/
class wsdl extends XMLSchema {
var $wsdl;
// define internal arrays of bindings, ports, operations, messages, etc.
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 = '';
// array of wsdl docs to import
var $import = array();
// parser vars
var $parser;
var $position = 0;
var $depth = 0;
var $depth_array = array();
var $usedNamespaces = array();
// for getting wsdl
var $proxyhost = '';
var $proxyport = '';
/**
* constructor
*
* @param string $wsdl WSDL document URL
* @access public
*/
function wsdl($wsdl = '',$proxyhost=false,$proxyport=false){
$this->wsdl = $wsdl;
$this->proxyhost = $proxyhost;
$this->proxyport = $proxyport;
// parse wsdl file
if ($wsdl != "") {
$this->debug('initial wsdl file: ' . $wsdl);
$this->parseWSDL($wsdl);
}
// imports
if (sizeof($this->import) > 0) {
foreach($this->import as $ns => $url) {
$this->debug('importing wsdl from ' . $url);
$this->parseWSDL($url);
}
}
}
/**
* parses the wsdl document
*
* @param string $wsdl path or URL
* @access private
*/
function parseWSDL($wsdl = '')
{
if ($wsdl == '') {
$this->debug('no wsdl passed to parseWSDL()!!');
$this->setError('no wsdl passed to parseWSDL()!!');
return false;
}
$this->debug('getting ' . $wsdl);
// parse $wsdl for url format
$wsdl_props = parse_url($wsdl);
if (isset($wsdl_props['host'])) {
// get 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);
}
if (isset($wsdl_props['user'])) {
$tr->setCredentials($wsdl_props['user'],$wsdl_props['pass']);
}
$wsdl_string = $tr->send('');
// catch errors
if($err = $tr->getError() ){
$this->debug('HTTP ERROR: '.$err);
$this->setError('HTTP ERROR: '.$err);
return false;
}
unset($tr);
/* $wsdl seems to be a valid url, not a file path, do an fsockopen/HTTP GET
$fsockopen_timeout = 30;
// check if a port value is supplied in url
if (isset($wsdl_props['port'])) {
// yes
$wsdl_url_port = $wsdl_props['port'];
} else {
// no, assign port number, based on url protocol (scheme)
switch ($wsdl_props['scheme']) {
case ('https') :
case ('ssl') :
case ('tls') :
$wsdl_url_port = 443;
break;
case ('http') :
default :
$wsdl_url_port = 80;
}
}
// FIXME: should implement SSL/TLS support here if CURL is available
if ($fp = fsockopen($wsdl_props['host'], $wsdl_url_port, $fsockopen_errnum, $fsockopen_errstr, $fsockopen_timeout)) {
// perform HTTP GET for WSDL file
// 10.9.02 - added poulter fix for doing this properly
$sHeader = "GET " . $wsdl_props['path'];
if (isset($wsdl_props['query'])) {
$sHeader .= "?" . $wsdl_props['query'];
}
$sHeader .= " HTTP/1.0\r\n";
if (isset($wsdl_props['user'])) {
$base64auth = base64_encode($wsdl_props['user'] . ":" . $wsdl_props['pass']);
$sHeader .= "Authorization: Basic $base64auth\r\n";
}
$sHeader .= "Host: " . $wsdl_props['host'] . ( isset($wsdl_props['port']) ? ":".$wsdl_props['port'] : "" ) . "\r\n\r\n";
fputs($fp, $sHeader);
while (fgets($fp, 1024) != "\r\n") {
// do nothing, just read/skip past HTTP headers
// FIXME: should actually detect HTTP response code, and act accordingly if error
// HTTP headers end with extra CRLF before content body
}
// read in WSDL just like regular fopen()
$wsdl_string = '';
while ($data = fread($fp, 32768)) {
$wsdl_string .= $data;
}
fclose($fp);
} else {
$this->setError('bad path to WSDL file.');
return false;
}
*/
} else {
// $wsdl seems to be a non-url file path, do the regular fopen
if ($fp = @fopen($wsdl, 'r')) {
$wsdl_string = '';
while ($data = fread($fp, 32768)) {
$wsdl_string .= $data;
}
fclose($fp);
} else {
$this->setError('bad path to WSDL file.');
return false;
}
}
// end new code added
// Create an XML parser.
$this->parser = xml_parser_create();
// Set the options for parsing the XML data.
// xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
// Set the object for the parser.
xml_set_object($this->parser, $this);
// Set the element handlers for the parser.
xml_set_element_handler($this->parser, 'start_element', 'end_element');
xml_set_character_data_handler($this->parser, 'character_data');
// Parse the XML file.
if (!xml_parse($this->parser, $wsdl_string, true)) {
// Display an error message.
$errstr = sprintf(
'XML error on line %d: %s',
xml_get_current_line_number($this->parser),
xml_error_string(xml_get_error_code($this->parser))
);
$this->debug('XML parse error: ' . $errstr);
$this->setError('Parser error: ' . $errstr);
return false;
}
// free the parser
xml_parser_free($this->parser);
// catch wsdl parse errors
if($this->getError()){
return false;
}
// add new data to operation data
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'] : '';
}
}
}
return true;
}
/**
* start-element handler
*
* @param string $parser XML parser object
* @param string $name element name
* @param string $attrs associative array of attributes
* @access private
*/
function start_element($parser, $name, $attrs)
{
if ($this->status == 'schema' || ereg('schema$', $name)) {
// $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")");
$this->status = 'schema';
$this->schemaStartElement($parser, $name, $attrs);
} else {
// position in the total number of elements, starting from 0
$pos = $this->position++;
$depth = $this->depth++;
// set self as current value for this depth
$this->depth_array[$depth] = $pos;
$this->message[$pos] = array('cdata' => '');
// get element prefix
if (ereg(':', $name)) {
// get ns prefix
$prefix = substr($name, 0, strpos($name, ':'));
// get ns
$namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : '';
// get unqualified name
$name = substr(strstr($name, ':'), 1);
}
if (count($attrs) > 0) {
foreach($attrs as $k => $v) {
// if ns declarations, add to class level array of valid namespaces
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';
}
} //
// expand each attribute
$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();
}
// find status, register data
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;
// merge input/output data
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':
// get ns prefix
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;
}
// set status
switch ($name) {
case "import":
if (isset($attrs['location'])) {
$this->import[$attrs['namespace']] = $attrs['location'];
}
break;
case 'types':
$this->status = 'schema';
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'])) {
// get binding name
if (strpos($attrs['name'], ':')) {
$this->currentBinding = $this->getLocalPart($attrs['name']);
} else {
$this->currentBinding = $attrs['name'];
}
$this->status = 'binding';
$this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']);
$this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']);
}
break;
case 'service':
$this->serviceName = $attrs['name'];
$this->status = 'service';
$this->debug('current service: ' . $this->serviceName);
break;
case 'definitions':
foreach ($attrs as $name => $value) {
$this->wsdl_info[$name] = $value;
}
break;
}
}
}
/**
* end-element handler
*
* @param string $parser XML parser object
* @param string $name element name
* @access private
*/
function end_element($parser, $name){
// unset schema status
if (ereg('types$', $name) || ereg('schema$', $name)) {
$this->status = "";
}
if ($this->status == 'schema') {
$this->schemaEndElement($parser, $name);
} else {
// bring depth down a notch
$this->depth--;
}
// end documentation
if ($this->documentation) {
$this->portTypes[$this->currentPortType][$this->currentPortOperation]['documentation'] = $this->documentation;
$this->documentation = false;
}
}
/**
* element content handler
*
* @param string $parser XML parser object
* @param string $data element content
* @access private
*/
function character_data($parser, $data)
{
$pos = isset($this->depth_array[$this->depth]) ? $this->depth_array[$this->depth] : 0;
if (isset($this->message[$pos]['cdata'])) {
$this->message[$pos]['cdata'] .= $data;
}
if ($this->documentation) {
$this->documentation .= $data;
}
}
function getBindingData($binding)
{
if (is_array($this->bindings[$binding])) {
return $this->bindings[$binding];
}
}
/**
* returns an assoc array of operation names => operation data
* NOTE: currently only supports multiple services of differing binding types
* This method needs some work
*
* @param string $bindingType eg: soap, smtp, dime (only soap is currently supported)
* @return array
* @access public
*/
function getOperations($bindingType = 'soap')
{
if ($bindingType == 'soap') {
$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
}
// loop thru ports
foreach($this->ports as $port => $portData) {
// binding type of port matches parameter
if ($portData['bindingType'] == $bindingType) {
// get binding
return $this->bindings[ $portData['binding'] ]['operations'];
}
}
return array();
}
/**
* returns an associative array of data necessary for calling an operation
*
* @param string $operation , name of operation
* @param string $bindingType , type of binding eg: soap
* @return array
* @access public
*/
function getOperationData($operation, $bindingType = 'soap')
{
if ($bindingType == 'soap') {
$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
}
// loop thru ports
foreach($this->ports as $port => $portData) {
// binding type of port matches parameter
if ($portData['bindingType'] == $bindingType) {
// get binding
//foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
foreach(array_keys($this->bindings[ $portData['binding'] ]['operations']) as $bOperation) {
if ($operation == $bOperation) {
$opData = $this->bindings[ $portData['binding'] ]['operations'][$operation];
return $opData;
}
}
}
}
}
/**
* serialize the parsed wsdl
*
* @return string , serialization of WSDL
* @access public
*/
function serialize()
{
$xml = '