Skip to content

Commit

Permalink
Added support for XML "nillable" when using SOAP overload extension. …
Browse files Browse the repository at this point in the history
…Mainly this means that the eval'd class method signatures have arguments with default values of NULL as defined by the WSDL so you can call a method like $Client->[method name]([arg1], [arg2] = NULL) and omit arg2.
  • Loading branch information
evictor committed Aug 9, 2012
1 parent 12044f4 commit c3ae947
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions SOAP/WSDL.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -508,19 +508,26 @@ function _validateString($string)
return preg_match('/^[\w_:#\/]+$/', $string); return preg_match('/^[\w_:#\/]+$/', $string);
} }


function _addArg(&$args, &$argarray, $argname) function _addArg(&$args, &$argarray, $argname, $nillable = false, &$nillableEls = array())
{ {
if ($args) { if ($args) {
$args .= ', '; $args .= ', ';
} }
$args .= '$' . $argname; $args .= '$' . $argname;
if($nillable) {
$args .= ' = NULL';
$nillableEls[] = $argname;
}
if (!$this->_validateString($argname)) { if (!$this->_validateString($argname)) {
return; return;
} }
if ($argarray) { if(!$nillable)
$argarray .= ', '; {
} if ($argarray) {
$argarray .= "'$argname' => $" . $argname; $argarray .= ', ';
}
$argarray .= "'$argname' => $" . $argname;
}
} }


function _elementArg(&$args, &$argarray, &$_argtype, $_argname) function _elementArg(&$args, &$argarray, &$_argtype, $_argname)
Expand Down Expand Up @@ -694,20 +701,38 @@ function generateProxyCode($port = '', $classname = '')
// XXX need to wrap the parameters in a // XXX need to wrap the parameters in a
// SOAP_Value. // SOAP_Value.
} }
$usingNillables = false;
$nillableEls = array();
if (isset($el['elements'])) { if (isset($el['elements'])) {
foreach ($el['elements'] as $elname => $elattrs) { foreach ($el['elements'] as $elname => $elattrs) {
$elname = $this->_sanitize($elname); $elname = $this->_sanitize($elname);
if((isset($elattrs['nillable']) && $elattrs['nillable'])
|| (isset($elattrs['minOccurs']) && $elattrs['minOccurs'] == 0))
{
// If you encounter one nillable, all subsequent
// arguments must be defaulted to NULL -- PHP
// function signature requirement for functions
// with parameters having defaults
$usingNillables = true;
}
// Is the element a complex type? // Is the element a complex type?
if (isset($this->complexTypes[$elattrs['namespace']][$elname])) { if (isset($this->complexTypes[$elattrs['namespace']][$elname])) {
$comments .= $this->_complexTypeArg($args, $argarray, $_argtype, $_argname); $comments .= $this->_complexTypeArg($args, $argarray, $_argtype, $_argname);
} else { } else {
$this->_addArg($args, $argarray, $elname); $this->_addArg($args, $argarray, $elname, $usingNillables, $nillableEls);
} }
} }
} }
if ($el['complex'] && $argarray) { if ($el['complex'] && $argarray) {
$wrapname = '{' . $this->namespaces[$_argtype['namespace']].'}' . $el['name']; $wrapname = '{' . $this->namespaces[$_argtype['namespace']].'}' . $el['name'];
$comments .= " \${$el['name']} = new SOAP_Value('$wrapname', false, \$v = array($argarray));\n"; $comments .= " \$v = array($argarray);\n";
if($usingNillables && !empty($nillableEls)) {
foreach($nillableEls as $nillableEl)
{
$comments .= " isset(\$$nillableEl) && \$v['$nillableEl'] = \$$nillableEl;\n";
}
}
$comments .= " \${$el['name']} = new SOAP_Value('$wrapname', false, \$v);\n";
$argarray = "'{$el['name']}' => \${$el['name']}"; $argarray = "'{$el['name']}' => \${$el['name']}";
} }
} else { } else {
Expand Down

0 comments on commit c3ae947

Please sign in to comment.