Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-picking a year's worth of forks #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ Copy of original library for supporting packagist composer.

More info at project webite http://nusoap.sourceforge.net/

This fork provides latest official sources taken form sourceforge VCS
and merged with deviservi/nusoap changes


1,358 changes: 705 additions & 653 deletions lib/changelog

Large diffs are not rendered by default.

42 changes: 14 additions & 28 deletions lib/class.nusoap_base.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
$Id: class.nusoap_base.php,v 1.56 2010/04/26 20:15:08 snichol Exp $
$Id: class.nusoap_base.php,v 1.58 2011/02/28 18:06:39 snichol Exp $

NuSOAP - Web Services Toolkit for PHP

Expand Down Expand Up @@ -71,15 +71,15 @@

// class variable emulation
// cf. http://www.webkreator.com/php/techniques/php-static-class-variables.html
$GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = 9;
$GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = 0;

/**
*
* nusoap_base
*
* @author Dietrich Ayala <[email protected]>
* @author Scott Nichol <[email protected]>
* @version $Id: class.nusoap_base.php,v 1.56 2010/04/26 20:15:08 snichol Exp $
* @version $Id: class.nusoap_base.php,v 1.58 2011/02/28 18:06:39 snichol Exp $
* @access public
*/
class nusoap_base {
Expand All @@ -96,14 +96,14 @@ class nusoap_base {
* @var string
* @access private
*/
var $version = '0.9.6';
var $version = '0.9.6dev';
/**
* CVS revision for HTTP headers.
*
* @var string
* @access private
*/
var $revision = '$Revision: 1.57 $';
var $revision = '$Revision: 1.58 $';
/**
* Current error string (manipulated by getError/setError)
*
Expand Down Expand Up @@ -148,8 +148,8 @@ class nusoap_base {
* @var string
* @access public
*/
var $soap_defencoding = 'ISO-8859-1';
//var $soap_defencoding = 'UTF-8';
//var $soap_defencoding = 'ISO-8859-1';
var $soap_defencoding = 'UTF-8';

/**
* namespaces in an array of prefix => uri
Expand Down Expand Up @@ -450,7 +450,7 @@ function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=fals
if (is_null($val)) {
$this->debug("serialize_val: serialize null");
if ($use == 'literal') {
// TODO: depends on minOccurs
// TODO: depends on minOccurs, nillable
$xml = "<$name$xmlns$atts/>";
$this->debug("serialize_val returning $xml");
return $xml;
Expand Down Expand Up @@ -902,6 +902,10 @@ function __toString() {
* @access public
*/
function timestamp_to_iso8601($timestamp,$utc=true){
if ($utc) {
return gmdate("Y-m-d\TH:i:s\Z", $timestamp);
}

$datestr = date('Y-m-d\TH:i:sO',$timestamp);
$pos = strrpos($datestr, "+");
if ($pos === FALSE) {
Expand All @@ -912,25 +916,7 @@ function timestamp_to_iso8601($timestamp,$utc=true){
$datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2);
}
}
if($utc){
$pattern = '/'.
'([0-9]{4})-'. // centuries & years CCYY-
'([0-9]{2})-'. // months MM-
'([0-9]{2})'. // days DD
'T'. // separator T
'([0-9]{2}):'. // hours hh:
'([0-9]{2}):'. // minutes mm:
'([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss...
'(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
'/';

if(preg_match($pattern,$datestr,$regs)){
return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]);
}
return false;
} else {
return $datestr;
}
return $datestr;
}

/**
Expand Down Expand Up @@ -993,4 +979,4 @@ function usleepWindows($usec)
}


?>
?>
5 changes: 4 additions & 1 deletion lib/class.soap_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @author Dietrich Ayala <[email protected]>
* @author Scott Nichol <[email protected]>
* @version $Id: class.soap_parser.php,v 1.42 2010/04/26 20:15:08 snichol Exp $
* @version $Id: class.soap_parser.php,v 1.43 2010/05/26 13:30:41 snichol Exp $
* @access public
*/
class nusoap_parser extends nusoap_base {
Expand Down Expand Up @@ -85,9 +85,12 @@ function nusoap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true){
}
} else {
$this->debug('No encoding specified in XML declaration');
$pos_end = strpos($xml, '?>', $pos_xml + 2);
$xml = substr($xml, 0, $pos_end) . " encoding=\"$encoding\"" . substr($xml, $pos_end);
}
} else {
$this->debug('No XML declaration');
$xml = "<?xml version=\"1.0\" encoding=\"$encoding\"?>" . $xml;
}
$this->debug('Entering nusoap_parser(), length='.strlen($xml).', encoding='.$encoding);
// Create an XML parser - why not xml_parser_create_ns?
Expand Down
166 changes: 141 additions & 25 deletions lib/class.soap_server.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @author Dietrich Ayala <[email protected]>
* @author Scott Nichol <[email protected]>
* @version $Id: class.soap_server.php,v 1.63 2010/04/26 20:15:08 snichol Exp $
* @version $Id: class.soap_server.php,v 1.67 2011/02/16 20:35:31 snichol Exp $
* @access public
*/
class nusoap_server extends nusoap_base {
Expand Down Expand Up @@ -136,6 +136,18 @@ class nusoap_server extends nusoap_base {
*/
var $result = 'successful';

/**
* dispatch map by operation element
* @var array
* @access private
*/
var $dispatchMapByOperationElement = array();
/**
* dispatch map by SOAP Action
* @var array
* @access private
*/
var $dispatchMapBySOAPAction = array();
/**
* assoc array of operations => opData; operations are added by the register()
* method or by parsing an external WSDL definition
Expand Down Expand Up @@ -522,36 +534,62 @@ function invoke_method() {
$this->debug('in invoke_method, no WSDL to validate method');
}

// if a . is present in $this->methodname, we see if there is a class in scope,
// which could be referred to. We will also distinguish between two deliminators,
// to allow methods to be called a the class or an instance
if (strpos($this->methodname, '..') > 0) {
$delim = '..';
} else if (strpos($this->methodname, '.') > 0) {
$delim = '.';
// check for an explicit mapping
if (isset($this->dispatchMapByOperationElement[$orig_methodname])) {
$map = $this->dispatchMapByOperationElement[$orig_methodname];
} elseif (isset($this->dispatchMapBySOAPAction[$this->SOAPAction])) {
$map = $this->dispatchMapBySOAPAction[$this->SOAPAction];
} else {
$delim = '';
$map = array();
}
$this->debug("in invoke_method, delim=$delim");

$class = '';
$method = '';
if (strlen($delim) > 0 && substr_count($this->methodname, $delim) == 1) {
$try_class = substr($this->methodname, 0, strpos($this->methodname, $delim));
if (class_exists($try_class)) {
// get the class and method name
$class = $try_class;
$method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim));
$this->debug("in invoke_method, class=$class method=$method delim=$delim");

if (count($map) > 0) {
// there is a mapping
if ($map['invoke_class'] != '') {
$class = $map['invoke_class'];
$delim = '..';
} elseif ($map['invoke_class_instance'] != '') {
$class = $map['invoke_class_instance'];
$delim = '.';
} else {
$this->debug("in invoke_method, class=$try_class not found");
$class = '';
$delim = '';
}
$try_class = $class;
$method = $map['invoke_function'];
} else {
$try_class = '';
$this->debug("in invoke_method, no class to try");
// if a . is present in $this->methodname, we see if there is a class in scope,
// which could be referred to. We will also distinguish between two deliminators,
// to allow methods to be called a the class or an instance
if (strpos($this->methodname, '..') > 0) {
$delim = '..';
} else if (strpos($this->methodname, '.') > 0) {
$delim = '.';
} else {
$delim = '';
}
$this->debug("in invoke_method, delim=$delim");

$class = '';
$method = '';
if (strlen($delim) > 0 && substr_count($this->methodname, $delim) == 1) {
$try_class = substr($this->methodname, 0, strpos($this->methodname, $delim));
if (class_exists($try_class)) {
// get the class and method name
$class = $try_class;
$method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim));
$this->debug("in invoke_method, class=$class method=$method delim=$delim");
} else {
$this->debug("in invoke_method, class=$try_class not found");
}
} else {
$try_class = '';
$this->debug("in invoke_method, no class to try");
}
}

// does method exist?
// TODO: use ReflectionClass for newer PHP versions in this part of the code
if ($class == '') {
if (!function_exists($this->methodname)) {
$this->debug("in invoke_method, function '$this->methodname' not found!");
Expand Down Expand Up @@ -671,6 +709,9 @@ function serialize_return() {
// $this->debug('wrap in element named ' . $name);
//}
$opParams = array($this->methodreturn);
} else {
$this->debug('no output parts, but wrap the method return in a simple array anyway');
$opParams = array($this->methodreturn);
}
$return_val = $this->wsdl->serializeRPCParameters($this->methodname,'output',$opParams);
$this->appendDebug($this->wsdl->getDebug());
Expand Down Expand Up @@ -752,7 +793,7 @@ function send_response() {
if ($this->fault) {
$payload = $this->fault->serialize();
$this->outgoing_headers[] = "HTTP/1.0 500 Internal Server Error";
$this->outgoing_headers[] = "Status: 500 Internal Server Error";
//$this->outgoing_headers[] = "Status: 500 Internal Server Error";
} else {
$payload = $this->responseSOAP;
// Some combinations of PHP+Web server allow the Status
Expand Down Expand Up @@ -943,6 +984,75 @@ function add_to_map($methodname,$in,$out){
$this->operations[$methodname] = array('name' => $methodname,'in' => $in,'out' => $out);
}

/**
* add an operation dispatch mapping
*
* (either $operation_element OR $soap_action should be specified)
* (one or neither of $invoke_class or $invoke_class_instance should be specified)
* ($invoke_function must always be specified)
*
* NOTE: this is separate from the register() method to support interface-first
* development of services; that technique normally uses an external WSDL file,
* so register() is never called.
*
* @param string $operation_element The XML element for the operation
* @param string $soap_action The SOAP Action for the operation
* @param string $invoke_function The function or method to invoke
* @param string $invoke_class The class on which to invoke as a class method
* @param string $invoke_class_instance The class on which to invoke as an instance method
* @return boolean true if added, false if not
* @access public
*/
function addDispatchMap($operation_element, $soap_action, $invoke_function, $invoke_class, $invoke_class_instance) {
// massage parameters
if (!is_string($operation_element))
$operation_element = '';
if (!is_string($soap_action))
$soap_action = '';
if (!is_string($invoke_class))
$invoke_class = '';
if (!is_string($invoke_class_instance))
$invoke_class_instance = '';
if (!is_string($invoke_function))
$invoke_function = '';

// validate parameters
if ($operation_element == '' && $soap_action == '') {
$this->debug('addDispatchMap: Neither operation_element nor soap_action specified');
return false;
}
if ($operation_element != '' && $soap_action != '') {
$this->debug('addDispatchMap: Both operation_element and soap_action specified');
return false;
}
if ($invoke_class != '' && $invoke_class_instance != '') {
$this->debug('addDispatchMap: Both invoke_class and invoke_class_instance specified');
return false;
}
if ($invoke_function == '') {
$this->debug('addDispatchMap: No value provided for invoke_function');
return false;
}

// create the map
$map['operation_element'] = $operation_element;
$map['soap_action'] = $soap_action;
$map['invoke_class'] = $invoke_class;
$map['invoke_class_instance'] = $invoke_class_instance;
$map['invoke_function'] = $invoke_function;

// add to the appropriate map hash
if ($operation_element != '') {
$this->dispatchMapByOperationElement[$operation_element] = $map;
$this->debug("addDispatchMap: Added map for operation_element $operation_element");
} else {
$this->dispatchMapBySOAPAction[$soap_action] = $map;
$this->debug("addDispatchMap: Added map for soap_action $soap_action");
}

return true;
}

/**
* register a service function with the server
*
Expand Down Expand Up @@ -1044,8 +1154,9 @@ function fault($faultcode,$faultstring,$faultactor='',$faultdetail=''){
* @param string $style optional (rpc|document) WSDL style (also specified by operation)
* @param string $transport optional SOAP transport
* @param mixed $schemaTargetNamespace optional 'types' targetNamespace for service schema or false
* @param string $serviceDocumentation documentation for the service
*/
function configureWSDL($serviceName,$namespace = false,$endpoint = false,$style='rpc', $transport = 'http://schemas.xmlsoap.org/soap/http', $schemaTargetNamespace = false)
function configureWSDL($serviceName,$namespace = false,$endpoint = false,$style='rpc', $transport = 'http://schemas.xmlsoap.org/soap/http', $schemaTargetNamespace = false, $serviceDocumentation = '')
{
global $HTTP_SERVER_VARS;

Expand Down Expand Up @@ -1085,13 +1196,18 @@ function configureWSDL($serviceName,$namespace = false,$endpoint = false,$style=
$endpoint = "$SCHEME://$SERVER_NAME$SERVER_PORT$SCRIPT_NAME";
}

if (false == $transport) {
$transport = 'http://schemas.xmlsoap.org/soap/http';
}

if(false == $schemaTargetNamespace) {
$schemaTargetNamespace = $namespace;
}

$this->wsdl = new wsdl;
$this->wsdl->serviceName = $serviceName;
$this->wsdl->endpoint = $endpoint;
$this->wsdl->serviceDocumentation = $serviceDocumentation;
$this->wsdl->namespaces['tns'] = $namespace;
$this->wsdl->namespaces['soap'] = 'http://schemas.xmlsoap.org/wsdl/soap/';
$this->wsdl->namespaces['wsdl'] = 'http://schemas.xmlsoap.org/wsdl/';
Expand Down
Loading