';
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();
/**
* constructor
*
* @param string $wsdl WSDL document URL
* @access public
*/
function wsdl($wsdl = '')
{
$this->wsdl = $wsdl;
// 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);
/**
* old
* 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;
* }
*/
// start new code added
// props go to robert tuttle for the wsdl-grabbing code
// parse $wsdl for url format
$wsdl_props = parse_url($wsdl);
if (isset($wsdl_props['host'])) {
// $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'] . "\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($this->bindings[$binding]['operations'][$operation]['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 = 'namespaces as $k => $v) {
$xml .= " xmlns:$k=\"$v\"";
}
// 10.9.02 - add poulter fix for wsdl and tns declarations
if (isset($this->namespaces['wsdl'])) {
$xml .= " xmlns=\"" . $this->namespaces['wsdl'] . "\"";
}
if (isset($this->namespaces['tns'])) {
$xml .= " targetNamespace=\"" . $this->namespaces['tns'] . "\"";
}
$xml .= '>';
// imports
if (sizeof($this->import) > 0) {
foreach($this->import as $ns => $url) {
$xml .= '';
}
}
// types
if (count($this->complexTypes)>=1) {
$xml .= '';
$xml .= $this->serializeSchema();
$xml .= '';
}
// messages
if (count($this->messages) >= 1) {
foreach($this->messages as $msgName => $msgParts) {
$xml .= '';
foreach($msgParts as $partName => $partType) {
// print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.' ';
if (strpos($partType, ':')) {
$typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType));
} elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) {
// print 'checking typemap: '.$this->XMLSchemaVersion.' ';
$typePrefix = 'xsd';
} else {
foreach($this->typemap as $ns => $types) {
if (isset($types[$partType])) {
$typePrefix = $this->getPrefixFromNamespace($ns);
}
}
if (!isset($typePrefix)) {
die("$partType has no namespace!");
}
}
$xml .= '';
}
$xml .= '';
}
}
// bindings & porttypes
if (count($this->bindings) >= 1) {
$binding_xml = '';
$portType_xml = '';
foreach($this->bindings as $bindingName => $attrs) {
$binding_xml .= '';
$binding_xml .= "';
$portType_xml .= '';
foreach($attrs["operations"] as $opName => $opParts) {
$binding_xml .= '';
$binding_xml .= '';
$binding_xml .= '';
$binding_xml .= '';
$binding_xml .= '';
$portType_xml .= '';
$portType_xml .= '';
$portType_xml .= '';
}
$portType_xml .= '';
$binding_xml .= '';
}
$xml .= $portType_xml . $binding_xml;
}
// services
$xml .= '';
if (count($this->ports) >= 1) {
foreach($this->ports as $pName => $attrs) {
$xml .= '';
$xml .= '';
$xml .= '';
}
}
$xml .= '';
return $xml . '';
}
/**
* serialize a PHP value according to a WSDL message definition
*
* TODO
* - multi-ref serialization
* - validate PHP values against type definitions, return errors if invalid
*
* @param string $ type name
* @param mixed $ param value
* @return mixed new param or false if initial value didn't validate
*/
function serializeRPCParameters($operation, $direction, $parameters)
{
$this->debug('in serializeRPCParameters with operation '.$operation.', direction '.$direction.' and '.count($parameters).' param(s), and xml schema version ' . $this->XMLSchemaVersion);
if ($direction != 'input' && $direction != 'output') {
$this->debug('The value of the \$direction argument needs to be either "input" or "output"');
$this->setError('The value of the \$direction argument needs to be either "input" or "output"');
return false;
}
if (!$opData = $this->getOperationData($operation)) {
$this->debug('Unable to retrieve WSDL data for operation: ' . $operation);
$this->setError('Unable to retrieve WSDL data for operation: ' . $operation);
return false;
}
$this->debug($this->varDump($opData));
// set input params
$xml = '';
if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
$this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)');
foreach($opData[$direction]['parts'] as $name => $type) {
// NOTE: add error handling here
// if serializeType returns false, then catch global error and fault
if (isset($parameters[$name])) {
$xml .= $this->serializeType($name, $type, $parameters[$name]);
} else {
$xml .= $this->serializeType($name, $type, array_shift($parameters));
}
}
}
return $xml;
}
/**
* serializes a PHP value according a given type definition
*
* @param string $name , name of type
* @param string $type , type of type, heh
* @param mixed $value , a native PHP value
* @return string serialization
* @access public
*/
function serializeType($name, $type, $value)
{
$this->debug("in serializeType: $name, $type, $value");
if (strpos($type, ':')) {
$uqType = substr($type, strrpos($type, ':') + 1);
$ns = substr($type, 0, strrpos($type, ':'));
$this->debug("got a prefixed type: $uqType, $ns");
if($ns == $this->XMLSchemaVersion ||
($this->getNamespaceFromPrefix($ns)) == $this->XMLSchemaVersion){
if ($uqType == 'boolean' && !$value) {
$value = 0;
} elseif ($uqType == 'boolean') {
$value = 1;
}
if ($this->charencoding && $uqType == 'string' && gettype($value) == 'string') {
$value = htmlspecialchars($value);
}
// it's a scalar
return "<$name xsi:type=\"" . $this->getPrefixFromNamespace($this->XMLSchemaVersion) . ":$uqType\">$value$name>";
}
} else {
$uqType = $type;
}
if(!$typeDef = $this->getTypeDef($uqType)){
$this->setError("$uqType is not a supported type.");
return false;
} else {
//foreach($typeDef as $k => $v) {
//$this->debug("typedef, $k: $v");
//}
}
$phpType = $typeDef['phpType'];
$this->debug("serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '') );
// if php type == struct, map value to the element names
if ($phpType == 'struct') {
$xml = "<$name xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">\n";
if (is_array($this->complexTypes[$uqType]['elements'])) {
foreach($this->complexTypes[$uqType]['elements'] as $eName => $attrs) {
// get value
if (isset($value[$eName])) {
$v = $value[$eName];
} elseif (is_array($value)) {
$v = array_shift($value);
}
if (!isset($attrs['type'])) {
$xml .= $this->serializeType($eName, $attrs['name'], $v);
} else {
$this->debug("calling serialize_val() for $eName, $v, " . $this->getLocalPart($attrs['type']));
$xml .= $this->serialize_val($v, $eName, $this->getLocalPart($attrs['type']), null, $this->getNamespaceFromPrefix($this->getPrefix($attrs['type'])));
}
}
}
$xml .= "$name>";
} elseif ($phpType == 'array') {
$rows = sizeof($value);
if (isset($typeDef['multidimensional'])) {
$nv = array();
foreach($value as $v) {
$cols = ',' . sizeof($v);
$nv = array_merge($nv, $v);
}
$value = $nv;
} else {
$cols = '';
}
if (is_array($value) && sizeof($value) >= 1) {
$contents = '';
foreach($value as $k => $v) {
$this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]");
if (strpos($typeDef['arrayType'], ':')) {
$contents .= $this->serializeType('item', $typeDef['arrayType'], $v);
} else {
$contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion);
}
}
$this->debug('contents: '.$this->varDump($contents));
}
$xml = "<$name xsi:type=\"".$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/').':Array" '.
$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/')
.':arrayType="'
.$this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType']))
.":".$this->getLocalPart($typeDef['arrayType'])."[$rows$cols]\">"
.$contents
."$name>";
}
$this->debug('returning: '.$this->varDump($xml));
return $xml;
}
/**
* register a service with the server
*
* @param string $methodname
* @param string $in assoc array of input values: key = param name, value = param type
* @param string $out assoc array of output values: key = param name, value = param type
* @param string $namespace
* @param string $soapaction
* @param string $style (rpc|literal)
* @access public
*/
function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '')
{
if ($style == 'rpc' && $use == 'encoded') {
$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
} else {
$encodingStyle = '';
}
// get binding
$this->bindings[ $this->serviceName . 'Binding' ]['operations'][$name] =
array(
'name' => $name,
'binding' => $this->serviceName . 'Binding',
'endpoint' => $this->endpoint,
'soapAction' => $soapaction,
'style' => $style,
'input' => array(
'use' => $use,
'namespace' => $namespace,
'encodingStyle' => $encodingStyle,
'message' => $name . 'Request',
'parts' => $in),
'output' => array(
'use' => $use,
'namespace' => $namespace,
'encodingStyle' => $encodingStyle,
'message' => $name . 'Response',
'parts' => $out),
'namespace' => $namespace,
'transport' => 'http://schemas.xmlsoap.org/soap/http',
'documentation' => $documentation);
// add portTypes
// add messages
if($in)
{
foreach($in as $pName => $pType)
{
if(strpos($pType,':')) {
$pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType);
}
$this->messages[$name.'Request'][$pName] = $pType;
}
}
if($out)
{
foreach($out as $pName => $pType)
{
if(strpos($pType,':')) {
$pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType);
}
$this->messages[$name.'Response'][$pName] = $pType;
}
}
return true;
}
}
?>
* @version v 0.6.3
* @access public
*/
class soap_parser extends nusoap_base {
var $xml = '';
var $xml_encoding = '';
var $method = '';
var $root_struct = '';
var $root_struct_name = '';
var $root_header = '';
var $document = '';
// determines where in the message we are (envelope,header,body,method)
var $status = '';
var $position = 0;
var $depth = 0;
var $default_namespace = '';
var $namespaces = array();
var $message = array();
var $parent = '';
var $fault = false;
var $fault_code = '';
var $fault_str = '';
var $fault_detail = '';
var $depth_array = array();
var $debug_flag = true;
var $soapresponse = NULL;
var $responseHeaders = '';
// for multiref parsing:
// array of id => pos
var $ids = array();
// array of id => hrefs => pos
var $multirefs = array();
/**
* constructor
*
* @param string $xml SOAP message
* @param string $encoding character encoding scheme of message
* @access public
*/
function soap_parser($xml,$encoding='UTF-8',$method=''){
$this->xml = $xml;
$this->xml_encoding = $encoding;
$this->method = $method;
// Check whether content has been read.
if(!empty($xml)){
$this->debug('Entering soap_parser()');
// Create an XML parser.
$this->parser = xml_parser_create($this->xml_encoding);
// 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,$xml,true)){
// Display an error message.
$err = 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('parse error: '.$err);
$this->errstr = $err;
} else {
$this->debug('parsed successfully, found root struct: '.$this->root_struct.' of name '.$this->root_struct_name);
// get final value
$this->soapresponse = $this->message[$this->root_struct]['result'];
// get header value
if($this->root_header != ""){
$this->responseHeaders = $this->message[$this->root_header]['result'];
}
}
xml_parser_free($this->parser);
} else {
$this->debug('xml was empty, didn\'t parse!');
$this->errstr = 'xml was empty, didn\'t parse!';
}
}
/**
* 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) {
// position in a total number of elements, starting from 0
// update class level pos
$pos = $this->position++;
// and set mine
$this->message[$pos] = array('pos' => $pos,'children'=>'','cdata'=>'');
// depth = how many levels removed from root?
// set mine as current global depth and increment global depth value
$this->message[$pos]['depth'] = $this->depth++;
// else add self as child to whoever the current parent is
if($pos != 0){
$this->message[$this->parent]['children'] .= '|'.$pos;
}
// set my parent
$this->message[$pos]['parent'] = $this->parent;
// set self as current parent
$this->parent = $pos;
// set self as current value for this depth
$this->depth_array[$this->depth] = $pos;
// get element prefix
if(strpos($name,':')){
// get ns prefix
$prefix = substr($name,0,strpos($name,':'));
// get unqualified name
$name = substr(strstr($name,':'),1);
}
// set status
if($name == 'Envelope'){
$this->status = 'envelope';
} elseif($name == 'Header'){
$this->root_header = $pos;
$this->status = 'header';
} elseif($name == 'Body'){
$this->status = 'body';
$this->body_position = $pos;
// set method
} elseif($this->status == 'body' && $pos == ($this->body_position+1)){
$this->status = 'method';
$this->root_struct_name = $name;
$this->root_struct = $pos;
$this->message[$pos]['type'] = 'struct';
$this->debug("found root struct $this->root_struct_name, pos $this->root_struct");
}
// set my status
$this->message[$pos]['status'] = $this->status;
// set name
$this->message[$pos]['name'] = htmlspecialchars($name);
// set attrs
$this->message[$pos]['attrs'] = $attrs;
// loop through atts, logging ns and type declarations
$attstr = '';
foreach($attrs as $key => $value){
$key_prefix = $this->getPrefix($key);
$key_localpart = $this->getLocalPart($key);
// if ns declarations, add to class level array of valid namespaces
if($key_prefix == 'xmlns'){
if(ereg('^http://www.w3.org/[0-9]{4}/XMLSchema$',$value)){
$this->XMLSchemaVersion = $value;
$this->namespaces['xsd'] = $this->XMLSchemaVersion;
$this->namespaces['xsi'] = $this->XMLSchemaVersion.'-instance';
}
$this->namespaces[$key_localpart] = $value;
// set method namespace
if($name == $this->root_struct_name){
$this->methodNamespace = $value;
}
// if it's a type declaration, set type
} elseif($key_localpart == 'type'){
$value_prefix = $this->getPrefix($value);
$value_localpart = $this->getLocalPart($value);
$this->message[$pos]['type'] = $value_localpart;
$this->message[$pos]['typePrefix'] = $value_prefix;
if(isset($this->namespaces[$value_prefix])){
$this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix];
}
// should do something here with the namespace of specified type?
} elseif($key_localpart == 'arrayType'){
$this->message[$pos]['type'] = 'array';
/* do arrayType ereg here
[1] arrayTypeValue ::= atype asize
[2] atype ::= QName rank*
[3] rank ::= '[' (',')* ']'
[4] asize ::= '[' length~ ']'
[5] length ::= nextDimension* Digit+
[6] nextDimension ::= Digit+ ','
*/
$expr = '([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]';
if(ereg($expr,$value,$regs)){
$this->message[$pos]['typePrefix'] = $regs[1];
$this->message[$pos]['arraySize'] = $regs[3];
$this->message[$pos]['arrayCols'] = $regs[4];
}
}
// log id
if($key == 'id'){
$this->ids[$value] = $pos;
}
// root
if($key_localpart == 'root' && $value == 1){
$this->status = 'method';
$this->root_struct_name = $name;
$this->root_struct = $pos;
$this->debug("found root struct $this->root_struct_name, pos $pos");
}
// for doclit
$attstr .= " $key=\"$value\"";
}
// get namespace - must be done after namespace atts are processed
if(isset($prefix)){
$this->message[$pos]['namespace'] = $this->namespaces[$prefix];
$this->default_namespace = $this->namespaces[$prefix];
} else {
$this->message[$pos]['namespace'] = $this->default_namespace;
}
if($this->status == 'header'){
$this->responseHeaders .= "<$name$attstr>";
} elseif($this->root_struct_name != ''){
$this->document .= "<$name$attstr>";
}
}
/**
* end-element handler
*
* @param string $parser XML parser object
* @param string $name element name
* @access private
*/
function end_element($parser, $name) {
// position of current element is equal to the last value left in depth_array for my depth
$pos = $this->depth_array[$this->depth--];
// get element prefix
if(strpos($name,':')){
// get ns prefix
$prefix = substr($name,0,strpos($name,':'));
// get unqualified name
$name = substr(strstr($name,':'),1);
}
// build to native type
if(isset($this->body_position) && $pos > $this->body_position){
// deal w/ multirefs
if(isset($this->message[$pos]['attrs']['href'])){
// get id
$id = substr($this->message[$pos]['attrs']['href'],1);
// add placeholder to href array
$this->multirefs[$id][$pos] = "placeholder";
// add set a reference to it as the result value
$this->message[$pos]['result'] =& $this->multirefs[$id][$pos];
// build complex values
} elseif($this->message[$pos]['children'] != ""){
$this->message[$pos]['result'] = $this->buildVal($pos);
} else {
$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']);
if(is_numeric($this->message[$pos]['cdata']) ){
if( strpos($this->message[$pos]['cdata'],'.') ){
$this->message[$pos]['result'] = doubleval($this->message[$pos]['cdata']);
} else {
$this->message[$pos]['result'] = intval($this->message[$pos]['cdata']);
}
} else {
$this->message[$pos]['result'] = $this->message[$pos]['cdata'];
}
}
}
// switch status
if($pos == $this->root_struct){
$this->status = 'body';
} elseif($name == 'Body'){
$this->status = 'header';
} elseif($name == 'Header'){
$this->status = 'envelope';
} elseif($name == 'Envelope'){
// resolve hrefs/ids
if(sizeof($this->multirefs) > 0){
foreach($this->multirefs as $id => $hrefs){
$this->debug('resolving multirefs for id: '.$id);
foreach($hrefs as $refPos => $ref){
$this->debug('resolving href at pos '.$refPos);
$this->multirefs[$id][$refPos] = $this->buildval($this->ids[$id]);
}
}
}
}
// set parent back to my parent
$this->parent = $this->message[$pos]['parent'];
// for doclit
if($this->status == 'header'){
$this->responseHeaders .= "$name>";
} elseif($pos >= $this->root_struct){
$this->document .= "$name>";
}
}
/**
* element content handler
*
* @param string $parser XML parser object
* @param string $data element content
* @access private
*/
function character_data($parser, $data){
$pos = $this->depth_array[$this->depth];
$this->message[$pos]['cdata'] .= $data;
// for doclit
if($this->status == 'header'){
$this->responseHeaders .= $data;
} else {
$this->document .= $data;
}
}
/**
* get the parsed message
*
* @return mixed
* @access public
*/
function get_response(){
return $this->soapresponse;
}
/**
* get the parsed headers
*
* @return string XML or empty if no headers
* @access public
*/
function getHeaders(){
return $this->responseHeaders;
}
/**
* decodes entities
*
* @param string $text string to translate
* @access private
*/
function decode_entities($text){
foreach($this->entities as $entity => $encoded){
$text = str_replace($encoded,$entity,$text);
}
return $text;
}
/**
* builds response structures for compound values (arrays/structs)
*
* @param string $pos position in node tree
* @access private
*/
function buildVal($pos){
if(!isset($this->message[$pos]['type'])){
$this->message[$pos]['type'] = '';
}
$this->debug('inside buildVal() for '.$this->message[$pos]['name']."(pos $pos) of type ".$this->message[$pos]['type']);
// if there are children...
if($this->message[$pos]['children'] != ''){
$children = explode('|',$this->message[$pos]['children']);
array_shift($children); // knock off empty
// md array
if(isset($this->message[$pos]['arrayCols']) && $this->message[$pos]['arrayCols'] != ''){
$r=0; // rowcount
$c=0; // colcount
foreach($children as $child_pos){
$this->debug("got an MD array element: $r, $c");
$params[$r][] = $this->message[$child_pos]['result'];
$c++;
if($c == $this->message[$pos]['arrayCols']){
$c = 0;
$r++;
}
}
// array
} elseif($this->message[$pos]['type'] == 'array' || $this->message[$pos]['type'] == 'Array'){
$this->debug('adding array '.$this->message[$pos]['name']);
foreach($children as $child_pos){
$params[] = $this->message[$child_pos]['result'];
}
// apache Map type: java hashtable
} elseif($this->message[$pos]['type'] == 'Map' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap'){
foreach($children as $child_pos){
$kv = explode("|",$this->message[$child_pos]['children']);
$params[$this->message[$kv[1]]['result']] = $this->message[$kv[2]]['result'];
}
// generic compound type
//} elseif($this->message[$pos]['type'] == 'SOAPStruct' || $this->message[$pos]['type'] == 'struct') {
} else {
foreach($children as $child_pos){
$params[$this->message[$child_pos]['name']] =& $this->message[$child_pos]['result'];
}
}
return is_array($params) ? $params : array();
} else {
$this->debug('no children');
if(strpos($this->message[$pos]['cdata'],'&')){
return strtr($this->message[$pos]['cdata'],array_flip($this->entities));
} else {
return $this->message[$pos]['cdata'];
}
}
}
}
?>call( string methodname [ ,array parameters] );
*
* // bye bye client
* unset($soapclient);
*
* @author Dietrich Ayala
* @version v 0.6.3
* @access public
*/
class nusoapclient extends nusoap_base {
var $username = '';
var $password = '';
var $requestHeaders = false;
var $responseHeaders;
var $endpoint;
var $error_str = false;
var $proxyhost = '';
var $proxyport = '';
var $xml_encoding = '';
var $http_encoding = false;
var $timeout = 0;
var $endpointType = '';
/**
* fault related variables
*
* @var fault
* @var faultcode
* @var faultstring
* @var faultdetail
* @access public
*/
var $fault, $faultcode, $faultstring, $faultdetail;
/**
* constructor
*
* @param string $endpoint SOAP server or WSDL URL
* @param bool $wsdl optional, set to true if using WSDL
* @param int $portName optional portName in WSDL document
* @access public
*/
function nusoapclient($endpoint,$wsdl = false){
$this->endpoint = $endpoint;
// make values
if($wsdl){
$this->endpointType = 'wsdl';
$this->wsdlFile = $this->endpoint;
// instantiate wsdl object and parse wsdl file
$this->debug('instantiating wsdl class with doc: '.$endpoint);
$this->wsdl =& new wsdl($this->wsdlFile);
$this->debug("wsdl debug: \n".$this->wsdl->debug_str);
// catch errors
if($errstr = $this->wsdl->getError()){
$this->debug('got wsdl error: '.$errstr);
$this->setError('wsdl error: '.$errstr);
} elseif($this->operations = $this->wsdl->getOperations()){
$this->debug( 'got '.count($this->operations).' operations from wsdl '.$this->wsdlFile);
} else {
$this->debug( 'getOperations returned false');
$this->setError('no operations defined in the WSDL document!');
}
}
}
/**
* calls method, returns PHP native type
*
* @param string $method SOAP server URL or path
* @param array $params array of parameters, can be associative or not
* @param string $namespace optional method namespace
* @param string $soapAction optional SOAPAction value
* @param boolean $headers optional array of soapval objects for headers
* @return mixed
* @access public
*/
function call($operation,$params=array(),$namespace='',$soapAction='',$headers=false){
$this->operation = $operation;
$this->fault = false;
$this->error_str = '';
$this->request = '';
$this->response = '';
$this->faultstring = '';
$this->faultcode = '';
$this->opData = array();
// if wsdl, get operation data and process parameters
if($this->endpointType == 'wsdl' && $opData = $this->getOperationData($operation)){
$this->opData = $opData;
$soapAction = $opData['soapAction'];
$this->endpoint = $opData['endpoint'];
$namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : 'http://testuri.org';
$style = $opData['style'];
// add ns to ns array
if($namespace != '' && !isset($this->wsdl->namespaces[$namespace])){
$this->wsdl->namespaces['nu'] = $namespace;
} else {
$namespace = 'http://testuri.org';
$this->wsdl->namespaces['nu'] = $namespace;
}
// serialize payload
if($style == 'rpc'){
$this->debug("serializing RPC params for operation $operation");
$payload = "<".$this->wsdl->getPrefixFromNamespace($namespace).":$operation>".
$this->wsdl->serializeRPCParameters($operation,'input',$params).
''.$this->wsdl->getPrefixFromNamespace($namespace).":$operation>";
} elseif($opData['input']['use'] == 'literal') {
$payload = is_array($params) ? array_shift($params) : $params;
}
// serialize envelope
$soapmsg = $this->serializeEnvelope($payload,$this->requestHeaders,$this->wsdl->usedNamespaces);
$this->debug("wsdl debug: \n".$this->wsdl->debug_str);
} elseif($this->endpointType == 'wsdl') {
$this->setError( 'operation '.$operation.' not present.');
$this->debug("operation '$operation' not present.");
$this->debug("wsdl debug: \n".$this->wsdl->debug_str);
return false;
// no wsdl
} else {
// make message
if(!isset($style)){
$style = 'rpc';
}
if($namespace == ''){
$namespace = 'http://testuri.org';
$this->wsdl->namespaces['ns1'] = $namespace;
}
// serialize envelope
$payload = '';
foreach($params as $k => $v){
$payload .= $this->serialize_val($v,$k);
}
$payload = "\n".$payload."\n";
$soapmsg = $this->serializeEnvelope($payload,$this->requestHeaders);
}
$this->debug("endpoint: $this->endpoint, soapAction: $soapAction, namespace: $namespace");
// send
$this->debug('sending msg (len: '.strlen($soapmsg).") w/ soapaction '$soapAction'...");
$return = $this->send($soapmsg,$soapAction,$this->timeout);
if($errstr = $this->getError()){
$this->debug('Error: '.$errstr);
return false;
} else {
$this->return = $return;
$this->debug('sent message successfully and got a(n) '.gettype($return).' back');
// fault?
if(is_array($return) && isset($return['faultcode'])){
$this->debug('got fault');
$this->setError($return['faultcode'].': '.$return['faultstring']);
$this->fault = true;
foreach($return as $k => $v){
$this->$k = $v;
$this->debug("$k = $v ");
}
return $return;
} else {
// array of return values
if(is_array($return)){
// multiple 'out' parameters
if(sizeof($return) > 1){
return $return;
}
// single 'out' parameter
return array_shift($return);
// nothing returned (ie, echoVoid)
} else {
return "";
}
}
}
}
/**
* get available data pertaining to an operation
*
* @param string $operation operation name
* @return array array of data pertaining to the operation
* @access public
*/
function getOperationData($operation){
if(isset($this->operations[$operation])){
return $this->operations[$operation];
}
}
/**
* send the SOAP message
*
* Note: if the operation has multiple return values
* the return value of this method will be an array
* of those values.
*
* @param string $msg a SOAPx4 soapmsg object
* @param string $soapaction SOAPAction value
* @param integer $timeout set timeout in seconds
* @return mixed native PHP types.
* @access private
*/
function send($msg, $soapaction = '', $timeout=0) {
// detect transport
switch(true){
// http(s)
case ereg('^http',$this->endpoint):
$this->debug('transporting via HTTP');
$http = new soap_transport_http($this->endpoint);
$http->setSOAPAction($soapaction);
if($this->proxyhost && $this->proxyport){
$http->setProxy($this->proxyhost,$this->proxyport);
}
if($this->username != '' && $this->password != '') {
$http->setCredentials($this->username,$this->password);
}
if($this->http_encoding != ''){
$http->setEncoding($this->http_encoding);
}
$this->debug('sending message, length: '.strlen($msg));
if(ereg('^http:',$this->endpoint)){
//if(strpos($this->endpoint,'http:')){
$response = $http->send($msg,$timeout);
} elseif(ereg('^https',$this->endpoint)){
//} elseif(strpos($this->endpoint,'https:')){
//if(phpversion() == '4.3.0-dev'){
//$response = $http->send($msg,$timeout);
//$this->request = $http->outgoing_payload;
//$this->response = $http->incoming_payload;
//} else
if (extension_loaded('curl')) {
$response = $http->sendHTTPS($msg,$timeout);
} else {
$this->setError('CURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS');
}
} else {
$this->setError('no http/s in endpoint url');
}
$this->request = $http->outgoing_payload;
$this->response = $http->incoming_payload;
$this->debug("transport debug data...\n".$http->debug_str);
if($err = $http->getError()){
$this->setError('HTTP Error: '.$err);
return false;
} elseif($this->getError()){
return false;
} else {
$this->debug('got response, length: '.strlen($response));
return $this->parseResponse($response);
}
break;
default:
$this->setError('no transport found, or selected transport is not yet supported!');
return false;
break;
}
}
/**
* processes SOAP message returned from server
*
* @param string unprocessed response data from server
* @return mixed value of the message, decoded into a PHP type
* @access private
*/
function parseResponse($data) {
$this->debug('Entering parseResponse(), about to create soap_parser instance');
$parser = new soap_parser($data,$this->xml_encoding,$this->operation);
// if parse errors
if($errstr = $parser->getError()){
$this->setError( $errstr);
// destroy the parser object
unset($parser);
return false;
} else {
// get SOAP headers
$this->responseHeaders = $parser->getHeaders();
// get decoded message
$return = $parser->get_response();
// add parser debug data to our debug
$this->debug($parser->debug_str);
// add document for doclit support
$this->document = $parser->document;
// destroy the parser object
unset($parser);
// return decode message
return $return;
}
}
/**
* set the SOAP headers
*
* @param $headers string XML
* @access public
*/
function setHeaders($headers){
$this->requestHeaders = $headers;
}
/**
* get the response headers
*
* @return mixed object SOAPx4 soapval object or empty if no headers
* @access public
*/
function getHeaders(){
if($this->responseHeaders != '') {
return $this->responseHeaders;
}
}
/**
* set proxy info here
*
* @param string $proxyhost
* @param string $proxyport
* @access public
*/
function setHTTPProxy($proxyhost, $proxyport) {
$this->proxyhost = $proxyhost;
$this->proxyport = $proxyport;
}
/**
* if authenticating, set user credentials here
*
* @param string $username
* @param string $password
* @access public
*/
function setCredentials($username, $password) {
$this->username = $username;
$this->password = $password;
}
/**
* use HTTP encoding
*
* @param string $enc
* @access public
*/
function setHTTPEncoding($enc='gzip, deflate'){
$this->http_encoding = $enc;
}
/**
* dynamically creates proxy class, allowing user to directly call methods from wsdl
*
* @return object soap_proxy object
* @access public
*/
function getProxy(){
foreach($this->operations as $operation => $opData){
if($operation != ''){
// create param string
if(sizeof($opData['input']['parts']) > 0){
foreach($opData['input']['parts'] as $name => $type){
$paramStr .= "\$$name,";
}
$paramStr = substr($paramStr,0,strlen($paramStr)-1);
}
$evalStr .= "function $operation ($paramStr){
// load params into array
\$params = array($paramStr);
return \$this->call('$operation',\$params,'".$opData['namespace']."','".$opData['soapAction']."');
}";
unset($paramStr);
}
}
$evalStr = 'class soap_proxy extends nusoapclient {
'.$evalStr.'
}';
//print "proxy class:
$evalStr
";
// eval the class
eval($evalStr);
// instantiate proxy object
$proxy = new soap_proxy("");
// transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice
$proxy->endpointType = 'wsdl';
$proxy->wsdlFile = $this->wsdlFile;
$proxy->wsdl = $this->wsdl;
$proxy->operations = $this->operations;
return $proxy;
}
}
?>