";
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;
}
/**
* serialize the parsed wsdl
*
* @param $debug mixed whether to put debug=1 in endpoint URL
* @return string , serialization of WSDL
* @access public
*/
function serialize($debug = 0)
{
$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 => $list) {
foreach ($list as $ii) {
if ($ii['location'] != '') {
$xml .= '';
} else {
$xml .= '';
}
}
}
}
// types
if (count($this->schemas)>=1) {
$xml .= '';
foreach ($this->schemas as $ns => $list) {
foreach ($list as $xs) {
$xml .= $xs->serializeSchema();
}
}
$xml .= '';
}
// messages
if (count($this->messages) >= 1) {
foreach($this->messages as $msgName => $msgParts) {
$xml .= '';
if(is_array($msgParts)){
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!");
}
}
$typeDef = $this->getTypeDef($this->getLocalPart($partType), $typePrefix);
if ($typeDef['typeClass'] == 'element') {
$elementortype = 'element';
} else {
$elementortype = 'type';
}
$xml .= 'getLocalPart($partType) . '" />';
}
}
$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 .= '';
if (isset($opParts['input']['encodingStyle']) && $opParts['input']['encodingStyle'] != '') {
$enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"';
} else {
$enc_style = '';
}
$binding_xml .= '';
if (isset($opParts['output']['encodingStyle']) && $opParts['output']['encodingStyle'] != '') {
$enc_style = ' encodingStyle="' . $opParts['output']['encodingStyle'] . '"';
} else {
$enc_style = '';
}
$binding_xml .= '';
$binding_xml .= '';
$portType_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('opData:');
$this->appendDebug($this->varDump($opData));
// Get encoding style for output and set to current
$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
$encodingStyle = $opData['output']['encodingStyle'];
$enc_style = $encodingStyle;
}
// set input params
$xml = '';
if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
$use = $opData[$direction]['use'];
$this->debug('have ' . count($opData[$direction]['parts']) . ' part(s) to serialize');
if (is_array($parameters)) {
$parametersArrayType = $this->isArraySimpleOrStruct($parameters);
$this->debug('have ' . count($parameters) . ' parameter(s) provided as ' . $parametersArrayType . ' to serialize');
foreach($opData[$direction]['parts'] as $name => $type) {
$this->debug('serializing part "'.$name.'" of type "'.$type.'"');
// Track encoding style
if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
$encodingStyle = $opData[$direction]['encodingStyle'];
$enc_style = $encodingStyle;
} else {
$enc_style = false;
}
// NOTE: add error handling here
// if serializeType returns false, then catch global error and fault
if ($parametersArrayType == 'arraySimple') {
$p = array_shift($parameters);
$this->debug('calling serializeType w/indexed param');
$xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
} elseif (isset($parameters[$name])) {
$this->debug('calling serializeType w/named param');
$xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
} else {
// TODO: only send nillable
$this->debug('calling serializeType w/null param');
$xml .= $this->serializeType($name, $type, null, $use, $enc_style);
}
}
} else {
$this->debug('no parameters passed.');
}
}
$this->debug("serializeRPCParameters returning: $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 serializeParameters($operation, $direction, $parameters)
{
$this->debug('in serializeParameters 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('opData:');
$this->appendDebug($this->varDump($opData));
// Get encoding style for output and set to current
$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
$encodingStyle = $opData['output']['encodingStyle'];
$enc_style = $encodingStyle;
}
// set input params
$xml = '';
if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
$use = $opData[$direction]['use'];
$this->debug("use=$use");
$this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)');
if (is_array($parameters)) {
$parametersArrayType = $this->isArraySimpleOrStruct($parameters);
$this->debug('have ' . $parametersArrayType . ' parameters');
foreach($opData[$direction]['parts'] as $name => $type) {
$this->debug('serializing part "'.$name.'" of type "'.$type.'"');
// Track encoding style
if(isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
$encodingStyle = $opData[$direction]['encodingStyle'];
$enc_style = $encodingStyle;
} else {
$enc_style = false;
}
// NOTE: add error handling here
// if serializeType returns false, then catch global error and fault
if ($parametersArrayType == 'arraySimple') {
$p = array_shift($parameters);
$this->debug('calling serializeType w/indexed param');
$xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
} elseif (isset($parameters[$name])) {
$this->debug('calling serializeType w/named param');
$xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
} else {
// TODO: only send nillable
$this->debug('calling serializeType w/null param');
$xml .= $this->serializeType($name, $type, null, $use, $enc_style);
}
}
} else {
$this->debug('no parameters passed.');
}
}
$this->debug("serializeParameters returning: $xml");
return $xml;
}
/**
* serializes a PHP value according a given type definition
*
* @param string $name , name of type (part)
* @param string $type , type of type, heh (type or element)
* @param mixed $value , a native PHP value (parameter value)
* @param string $use , use for part (encoded|literal)
* @param string $encodingStyle , use to add encoding changes to serialisation
* @param boolean $unqualified , a kludge for what should be form handling
* @return string serialization
* @access public
*/
function serializeType($name, $type, $value, $use='encoded', $encodingStyle=false, $unqualified=false)
{
$this->debug("in serializeType: $name, $type, $use, $encodingStyle, " . ($unqualified ? "unqualified" : "qualified"));
$this->debug("value:");
$this->appendDebug($this->varDump($value));
if($use == 'encoded' && $encodingStyle) {
$encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"';
}
// if a soap_val has been supplied, let its type override the WSDL
if (is_object($value) && get_class($value) == 'soapval') {
// TODO: get attributes from soapval?
if ($value->type_ns) {
$type = $value->type_ns . ':' . $value->type;
$forceType = true;
$this->debug("in serializeType: soapval overrides type to $type");
} elseif ($value->type) {
$type = $value->type;
$forceType = true;
$this->debug("in serializeType: soapval overrides type to $type");
} else {
$forceType = false;
$this->debug("in serializeType: soapval does not override type");
}
$attrs = $value->attributes;
$value = $value->value;
$this->debug("in serializeType: soapval overrides value to $value");
if ($attrs) {
foreach ($attrs as $n => $v) {
$value['!' . $n] = $v;
}
$this->debug("in serializeType: soapval provides attributes");
}
} else {
$forceType = false;
}
$xml = '';
if (strpos($type, ':')) {
$uqType = substr($type, strrpos($type, ':') + 1);
$ns = substr($type, 0, strrpos($type, ':'));
$this->debug("got a prefixed type: $uqType, $ns");
if ($this->getNamespaceFromPrefix($ns)) {
$ns = $this->getNamespaceFromPrefix($ns);
$this->debug("expanded prefixed type: $uqType, $ns");
}
if($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/'){
$this->debug('type namespace indicates XML Schema or SOAP Encoding type');
if ($unqualified && $use == 'literal') {
$elementNS = " xmlns=\"\"";
} else {
$elementNS = '';
}
if (is_null($value)) {
if ($use == 'literal') {
// TODO: depends on nillable
$xml = "<$name$elementNS/>";
} else {
$xml = "<$name$elementNS xsi:nil=\"true\"/>";
}
$this->debug("serializeType returning: $xml");
return $xml;
}
if ($uqType == 'boolean' && !$value) {
$value = 'false';
} elseif ($uqType == 'boolean') {
$value = 'true';
}
if ($uqType == 'string' && gettype($value) == 'string') {
$value = $this->expandEntities($value);
}
if (($uqType == 'long' || $uqType == 'unsignedLong') && gettype($value) == 'double') {
$value = sprintf("%.0lf", $value);
}
// it's a scalar
// TODO: what about null/nil values?
// check type isn't a custom type extending xmlschema namespace
if (!$this->getTypeDef($uqType, $ns)) {
if ($use == 'literal') {
if ($forceType) {
$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value$name>";
} else {
$xml = "<$name$elementNS>$value$name>";
}
} else {
$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value$name>";
}
$this->debug("serializeType returning: $xml");
return $xml;
}
$this->debug('custom type extends XML Schema or SOAP Encoding namespace (yuck)');
} else if ($ns == 'http://xml.apache.org/xml-soap') {
if ($uqType == 'Map') {
$contents = '';
foreach($value as $k => $v) {
$this->debug("serializing map element: key $k, value $v");
$contents .= '';
$contents .= $this->serialize_val($k,'key',false,false,false,false,$use);
$contents .= $this->serialize_val($v,'value',false,false,false,false,$use);
$contents .= '';
}
if ($use == 'literal') {
if ($forceType) {
$xml = "<$name xsi:type=\"" . $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap') . ":$uqType\">$contents$name>";
} else {
$xml = "<$name>$contents$name>";
}
} else {
$xml = "<$name xsi:type=\"" . $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap') . ":$uqType\"$encodingStyle>$contents$name>";
}
$this->debug("serializeType returning: $xml");
return $xml;
}
}
} else {
$this->debug("No namespace for type $type");
$ns = '';
$uqType = $type;
}
if(!$typeDef = $this->getTypeDef($uqType, $ns)){
$this->setError("$type ($uqType) is not a supported type.");
$this->debug("$type ($uqType) is not a supported type.");
return false;
} else {
$this->debug("typedef:");
$this->appendDebug($this->varDump($typeDef));
}
$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') {
if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') {
$elementName = $uqType;
if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
$elementNS = " xmlns=\"$ns\"";
} else {
$elementNS = " xmlns=\"\"";
}
} else {
$elementName = $name;
if ($unqualified) {
$elementNS = " xmlns=\"\"";
} else {
$elementNS = '';
}
}
if (is_null($value)) {
if ($use == 'literal') {
// TODO: depends on nillable
$xml = "<$elementName$elementNS/>";
} else {
$xml = "<$elementName$elementNS xsi:nil=\"true\"/>";
}
$this->debug("serializeType returning: $xml");
return $xml;
}
$elementAttrs = $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType);
if ($use == 'literal') {
if ($forceType) {
$xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">";
} else {
$xml = "<$elementName$elementNS$elementAttrs>";
}
} else {
$xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>";
}
$xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
$xml .= "$elementName>";
} elseif ($phpType == 'array') {
if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
$elementNS = " xmlns=\"$ns\"";
} else {
if ($unqualified) {
$elementNS = " xmlns=\"\"";
} else {
$elementNS = '';
}
}
if (is_null($value)) {
if ($use == 'literal') {
// TODO: depends on nillable
$xml = "<$name$elementNS/>";
} else {
$xml = "<$name$elementNS xsi:nil=\"true\"/>";
}
$this->debug("serializeType returning: $xml");
return $xml;
}
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) {
$rows = sizeof($value);
$contents = '';
foreach($value as $k => $v) {
$this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]");
//if (strpos($typeDef['arrayType'], ':') ) {
if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) {
$contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);
} else {
$contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
}
}
} else {
$rows = 0;
$contents = null;
}
// TODO: for now, an empty value will be serialized as a zero element
// array. Revisit this when coding the handling of null/nil values.
if ($use == 'literal') {
$xml = "<$name$elementNS>"
.$contents
."$name>";
} else {
$xml = "<$name$elementNS 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>";
}
} elseif ($phpType == 'scalar') {
if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
$elementNS = " xmlns=\"$ns\"";
} else {
if ($unqualified) {
$elementNS = " xmlns=\"\"";
} else {
$elementNS = '';
}
}
if ($use == 'literal') {
if ($forceType) {
$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value$name>";
} else {
$xml = "<$name$elementNS>$value$name>";
}
} else {
$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value$name>";
}
}
$this->debug("serializeType returning: $xml");
return $xml;
}
/**
* serializes the attributes for a complexType
*
* @param array $typeDef
* @param mixed $value , a native PHP value (parameter value)
* @param string $ns the namespace of the type
* @param string $uqType the local part of the type
* @return string serialization
* @access public
*/
function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType) {
$xml = '';
if (isset($typeDef['attrs']) && is_array($typeDef['attrs'])) {
$this->debug("serialize attributes for XML Schema type $ns:$uqType");
if (is_array($value)) {
$xvalue = $value;
} elseif (is_object($value)) {
$xvalue = get_object_vars($value);
} else {
$this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
$xvalue = array();
}
foreach ($typeDef['attrs'] as $aName => $attrs) {
if (isset($xvalue['!' . $aName])) {
$xname = '!' . $aName;
$this->debug("value provided for attribute $aName with key $xname");
} elseif (isset($xvalue[$aName])) {
$xname = $aName;
$this->debug("value provided for attribute $aName with key $xname");
} elseif (isset($attrs['default'])) {
$xname = '!' . $aName;
$xvalue[$xname] = $attrs['default'];
$this->debug('use default value of ' . $xvalue[$aName] . ' for attribute ' . $aName);
} else {
$xname = '';
$this->debug("no value provided for attribute $aName");
}
if ($xname) {
$xml .= " $aName=\"" . $xvalue[$xname] . "\"";
}
}
} else {
$this->debug("no attributes to serialize for XML Schema type $ns:$uqType");
}
if (isset($typeDef['extensionBase'])) {
$ns = $this->getPrefix($typeDef['extensionBase']);
$uqType = $this->getLocalPart($typeDef['extensionBase']);
if ($this->getNamespaceFromPrefix($ns)) {
$ns = $this->getNamespaceFromPrefix($ns);
}
if ($typeDef = $this->getTypeDef($uqType, $ns)) {
$this->debug("serialize attributes for extension base $ns:$uqType");
$xml .= $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType);
} else {
$this->debug("extension base $ns:$uqType is not a supported type");
}
}
return $xml;
}
/**
* serializes the elements for a complexType
*
* @param array $typeDef
* @param mixed $value , a native PHP value (parameter value)
* @param string $ns the namespace of the type
* @param string $uqType the local part of the type
* @param string $use , use for part (encoded|literal)
* @param string $encodingStyle , use to add encoding changes to serialisation
* @return string serialization
* @access public
*/
function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use='encoded', $encodingStyle=false) {
$xml = '';
if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
$this->debug("serialize elements for XML Schema type $ns:$uqType");
if (is_array($value)) {
$xvalue = $value;
} elseif (is_object($value)) {
$xvalue = get_object_vars($value);
} else {
$this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
$xvalue = array();
}
// toggle whether all elements are present - ideally should validate against schema
if (count($typeDef['elements']) != count($xvalue)){
$optionals = true;
}
foreach ($typeDef['elements'] as $eName => $attrs) {
if (!isset($xvalue[$eName])) {
if (isset($attrs['default'])) {
$xvalue[$eName] = $attrs['default'];
$this->debug('use default value of ' . $xvalue[$eName] . ' for element ' . $eName);
}
}
// if user took advantage of a minOccurs=0, then only serialize named parameters
if (isset($optionals) && !isset($xvalue[$eName])){
// do nothing
$this->debug("no value provided for complexType element $eName, so serialize nothing");
} else {
// get value
if (isset($xvalue[$eName])) {
$v = $xvalue[$eName];
} else {
$v = null;
}
if (isset($attrs['form'])) {
$unqualified = ($attrs['form'] == 'unqualified');
} else {
$unqualified = false;
}
// TODO: if maxOccurs > 1 (not just unbounded), then allow serialization of an array
if (isset($attrs['maxOccurs']) && $attrs['maxOccurs'] == 'unbounded' && isset($v) && is_array($v) && $this->isArraySimpleOrStruct($v) == 'arraySimple') {
$vv = $v;
foreach ($vv as $k => $v) {
if (isset($attrs['type'])) {
// serialize schema-defined type
$xml .= $this->serializeType($eName, $attrs['type'], $v, $use, $encodingStyle, $unqualified);
} else {
// serialize generic type
$this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
$xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
}
}
} else {
if (isset($attrs['type'])) {
// serialize schema-defined type
$xml .= $this->serializeType($eName, $attrs['type'], $v, $use, $encodingStyle, $unqualified);
} else {
// serialize generic type
$this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
$xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
}
}
}
}
} else {
$this->debug("no elements to serialize for XML Schema type $ns:$uqType");
}
if (isset($typeDef['extensionBase'])) {
$ns = $this->getPrefix($typeDef['extensionBase']);
$uqType = $this->getLocalPart($typeDef['extensionBase']);
if ($this->getNamespaceFromPrefix($ns)) {
$ns = $this->getNamespaceFromPrefix($ns);
}
if ($typeDef = $this->getTypeDef($uqType, $ns)) {
$this->debug("serialize elements for extension base $ns:$uqType");
$xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
} else {
$this->debug("extension base $ns:$uqType is not a supported type");
}
}
return $xml;
}
/**
* adds an XML Schema complex type to the WSDL types
*
* @param name
* @param typeClass (complexType|simpleType|attribute)
* @param phpType: currently supported are array and struct (php assoc array)
* @param compositor (all|sequence|choice)
* @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
* @param elements = array ( name = array(name=>'',type=>'') )
* @param attrs = array(
* array(
* 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
* "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
* )
* )
* @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
* @see xmlschema
*
*/
function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType='') {
if (count($elements) > 0) {
foreach($elements as $n => $e){
// expand each element
foreach ($e as $k => $v) {
$k = strpos($k,':') ? $this->expandQname($k) : $k;
$v = strpos($v,':') ? $this->expandQname($v) : $v;
$ee[$k] = $v;
}
$eElements[$n] = $ee;
}
$elements = $eElements;
}
if (count($attrs) > 0) {
foreach($attrs as $n => $a){
// expand each attribute
foreach ($a as $k => $v) {
$k = strpos($k,':') ? $this->expandQname($k) : $k;
$v = strpos($v,':') ? $this->expandQname($v) : $v;
$aa[$k] = $v;
}
$eAttrs[$n] = $aa;
}
$attrs = $eAttrs;
}
$restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
$arrayType = strpos($arrayType,':') ? $this->expandQname($arrayType) : $arrayType;
$typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
$this->schemas[$typens][0]->addComplexType($name,$typeClass,$phpType,$compositor,$restrictionBase,$elements,$attrs,$arrayType);
}
/**
* adds an XML Schema simple type to the WSDL types
*
* @param name
* @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
* @param typeClass (simpleType)
* @param phpType: (scalar)
* @see xmlschema
*
*/
function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar') {
$restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
$typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
$this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType);
}
/**
* adds an element to the WSDL types
*
* @param name
* @param array $attrs attributes that must include name and type
* @see xmlschema
*/
function addElement($attrs) {
$typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
$this->schemas[$typens][0]->addElement($attrs);
}
/**
* 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 optional The namespace for the operation
* @param string $soapaction optional The soapaction for the operation
* @param string $style (rpc|document) optional The style for the operation
* @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now)
* @param string $documentation optional The description to include in the WSDL
* @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 = '';
}
if ($style == 'document') {
$elements = array();
foreach ($in as $n => $t) {
$elements[$n] = array('name' => $n, 'type' => $t);
}
$this->addComplexType($name . 'RequestType', 'complexType', 'struct', 'all', '', $elements);
$this->addElement(array('name' => $name, 'type' => $name . 'RequestType'));
$in = array('parameters' => 'tns:' . $name);
$elements = array();
foreach ($out as $n => $t) {
$elements[$n] = array('name' => $n, 'type' => $t);
}
$this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements);
$this->addElement(array('name' => $name . 'Response', 'type' => $name . 'ResponseType'));
$out = array('parameters' => 'tns:' . $name . 'Response');
}
// 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;
}
} else {
$this->messages[$name.'Request']= '0';
}
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;
}
} else {
$this->messages[$name.'Response']= '0';
}
return true;
}
}
?>
* @version $Id: nusoap.php 50 2007-06-24 08:58:52Z tsigo $
* @access public
*/
class soap_parser extends nusoap_base {
var $xml = '';
var $xml_encoding = '';
var $method = '';
var $root_struct = '';
var $root_struct_name = '';
var $root_struct_namespace = '';
var $root_header = '';
var $document = ''; // incoming SOAP body (text)
// 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 = ''; // incoming SOAP headers (text)
var $body_position = 0;
// for multiref parsing:
// array of id => pos
var $ids = array();
// array of id => hrefs => pos
var $multirefs = array();
// toggle for auto-decoding element content
var $decode_utf8 = true;
/**
* constructor
*
* @param string $xml SOAP message
* @param string $encoding character encoding scheme of message
* @param string $method
* @param string $decode_utf8 whether to decode UTF-8 to ISO-8859-1
* @access public
*/
function soap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true){
$this->xml = $xml;
$this->xml_encoding = $encoding;
$this->method = $method;
$this->decode_utf8 = $decode_utf8;
// Check whether content has been read.
if(!empty($xml)){
// Check XML encoding
$pos_xml = strpos($xml, '', $pos_xml + 2) - $pos_xml + 1);
if (preg_match("/encoding=[\"']([^\"']*)[\"']/", $xml_decl, $res)) {
$xml_encoding = $res[1];
if (strtoupper($xml_encoding) != $encoding) {
$err = "Charset from HTTP Content-Type '" . $encoding . "' does not match encoding from XML declaration '" . $xml_encoding . "'";
$this->debug($err);
if ($encoding != 'ISO-8859-1' || strtoupper($xml_encoding) != 'UTF-8') {
$this->setError($err);
return;
}
// when HTTP says ISO-8859-1 (the default) and XML says UTF-8 (the typical), assume the other endpoint is just sloppy and proceed
} else {
$this->debug('Charset from HTTP Content-Type matches encoding from XML declaration');
}
} else {
$this->debug('No encoding specified in XML declaration');
}
} else {
$this->debug('No XML declaration');
}
$this->debug('Entering soap_parser(), length='.strlen($xml).', encoding='.$encoding);
// Create an XML parser - why not xml_parser_create_ns?
$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);
xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->xml_encoding);
// 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 parsing SOAP payload on line %d: %s',
xml_get_current_line_number($this->parser),
xml_error_string(xml_get_error_code($this->parser)));
$this->debug($err);
$this->debug("XML payload:\n" . $xml);
$this->setError($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: no, because this is documented as XML string
// if($this->root_header != '' && isset($this->message[$this->root_header]['result'])){
// $this->responseHeaders = $this->message[$this->root_header]['result'];
// }
// resolve hrefs/ids
if(sizeof($this->multirefs) > 0){
foreach($this->multirefs as $id => $hrefs){
$this->debug('resolving multirefs for id: '.$id);
$idVal = $this->buildVal($this->ids[$id]);
unset($idVal['!id']);
foreach($hrefs as $refPos => $ref){
$this->debug('resolving href at pos '.$refPos);
$this->multirefs[$id][$refPos] = $idVal;
}
}
}
}
xml_parser_free($this->parser);
} else {
$this->debug('xml was empty, didn\'t parse!');
$this->setError('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];
} else if(isset($attrs['xmlns:'.$value_prefix])) {
$this->message[$pos]['type_namespace'] = $attrs['xmlns:'.$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]['arrayTypePrefix'] = $regs[1];
if (isset($this->namespaces[$regs[1]])) {
$this->message[$pos]['arrayTypeNamespace'] = $this->namespaces[$regs[1]];
} else if (isset($attrs['xmlns:'.$regs[1]])) {
$this->message[$pos]['arrayTypeNamespace'] = $attrs['xmlns:'.$regs[1]];
}
$this->message[$pos]['arrayType'] = $regs[2];
$this->message[$pos]['arraySize'] = $regs[3];
$this->message[$pos]['arrayCols'] = $regs[4];
}
// specifies nil value (or not)
} elseif ($key_localpart == 'nil'){
$this->message[$pos]['nil'] = ($value == 'true' || $value == '1');
// some other attribute
} elseif ($key != 'href' && $key != 'xmlns' && $key_localpart != 'encodingStyle' && $key_localpart != 'root') {
$this->message[$pos]['xattrs']['!' . $key] = $value;
}
if ($key == 'xmlns') {
$this->default_namespace = $value;
}
// 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'){
if ($this->root_header != $pos) {
$this->responseHeaders .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
}
} elseif($this->root_struct_name != ''){
$this->document .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$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 complexType values
} elseif($this->message[$pos]['children'] != ''){
// if result has already been generated (struct/array)
if(!isset($this->message[$pos]['result'])){
$this->message[$pos]['result'] = $this->buildVal($pos);
}
// build complexType values of attributes and possibly simpleContent
} elseif (isset($this->message[$pos]['xattrs'])) {
if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
$this->message[$pos]['xattrs']['!'] = null;
} elseif (isset($this->message[$pos]['cdata']) && $this->message[$pos]['cdata'] != '') {
if (isset($this->message[$pos]['type'])) {
$this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
} else {
$parent = $this->message[$pos]['parent'];
if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
$this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
} else {
$this->message[$pos]['xattrs']['!'] = $this->message[$pos]['cdata'];
}
}
}
$this->message[$pos]['result'] = $this->message[$pos]['xattrs'];
// set value of simpleType (or nil complexType)
} else {
//$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']);
if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
$this->message[$pos]['xattrs']['!'] = null;
} elseif (isset($this->message[$pos]['type'])) {
$this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
} else {
$parent = $this->message[$pos]['parent'];
if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
$this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
} else {
$this->message[$pos]['result'] = $this->message[$pos]['cdata'];
}
}
/* add value to parent's result, if parent is struct/array
$parent = $this->message[$pos]['parent'];
if($this->message[$parent]['type'] != 'map'){
if(strtolower($this->message[$parent]['type']) == 'array'){
$this->message[$parent]['result'][] = $this->message[$pos]['result'];
} else {
$this->message[$parent]['result'][$this->message[$pos]['name']] = $this->message[$pos]['result'];
}
}
*/
}
}
// for doclit
if($this->status == 'header'){
if ($this->root_header != $pos) {
$this->responseHeaders .= "" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
}
} elseif($pos >= $this->root_struct){
$this->document .= "" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
}
// switch status
if($pos == $this->root_struct){
$this->status = 'body';
$this->root_struct_namespace = $this->message[$pos]['namespace'];
} elseif($name == 'Body'){
$this->status = 'envelope';
} elseif($name == 'Header'){
$this->status = 'envelope';
} elseif($name == 'Envelope'){
//
}
// set parent back to my parent
$this->parent = $this->message[$pos]['parent'];
}
/**
* 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];
if ($this->xml_encoding=='UTF-8'){
// TODO: add an option to disable this for folks who want
// raw UTF-8 that, e.g., might not map to iso-8859-1
// TODO: this can also be handled with xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");
if($this->decode_utf8){
$data = utf8_decode($data);
}
}
$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;
}
/**
* decodes simple types into PHP variables
*
* @param string $value value to decode
* @param string $type XML type to decode
* @param string $typens XML type namespace to decode
* @access private
*/
function decodeSimple($value, $type, $typens) {
// TODO: use the namespace!
if ((!isset($type)) || $type == 'string' || $type == 'long' || $type == 'unsignedLong') {
return (string) $value;
}
if ($type == 'int' || $type == 'integer' || $type == 'short' || $type == 'byte') {
return (int) $value;
}
if ($type == 'float' || $type == 'double' || $type == 'decimal') {
return (double) $value;
}
if ($type == 'boolean') {
if (strtolower($value) == 'false' || strtolower($value) == 'f') {
return false;
}
return (boolean) $value;
}
if ($type == 'base64' || $type == 'base64Binary') {
return base64_decode($value);
}
// obscure numeric types
if ($type == 'nonPositiveInteger' || $type == 'negativeInteger'
|| $type == 'nonNegativeInteger' || $type == 'positiveInteger'
|| $type == 'unsignedInt'
|| $type == 'unsignedShort' || $type == 'unsignedByte') {
return (int) $value;
}
// everything else
return (string) $value;
}
/**
* 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 {
// Apache Vector type: treat as an array
if ($this->message[$pos]['type'] == 'Vector' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap') {
$notstruct = 1;
} else {
$notstruct = 0;
}
//
foreach($children as $child_pos){
if($notstruct){
$params[] = &$this->message[$child_pos]['result'];
} else {
if (isset($params[$this->message[$child_pos]['name']])) {
// de-serialize repeated element name into an array
if ((!is_array($params[$this->message[$child_pos]['name']])) || (!isset($params[$this->message[$child_pos]['name']][0]))) {
$params[$this->message[$child_pos]['name']] = array($params[$this->message[$child_pos]['name']]);
}
$params[$this->message[$child_pos]['name']][] = &$this->message[$child_pos]['result'];
} else {
$params[$this->message[$child_pos]['name']] = &$this->message[$child_pos]['result'];
}
}
}
}
if (isset($this->message[$pos]['xattrs'])) {
foreach ($this->message[$pos]['xattrs'] as $n => $v) {
$params[$n] = $v;
}
}
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 $Id: nusoap.php 50 2007-06-24 08:58:52Z tsigo $
* @access public
*/
class soapclient extends nusoap_base {
var $username = '';
var $password = '';
var $authtype = '';
var $certRequest = array();
var $requestHeaders = false; // SOAP headers in request (text)
var $responseHeaders = ''; // SOAP headers from response (incomplete namespace resolution) (text)
var $document = ''; // SOAP body response portion (incomplete namespace resolution) (text)
var $endpoint;
var $proxyhost = '';
var $proxyport = '';
var $proxyusername = '';
var $proxypassword = '';
var $xml_encoding = ''; // character set encoding of incoming (response) messages
var $http_encoding = false;
var $timeout = 0; // HTTP connection timeout
var $response_timeout = 30; // HTTP response timeout
var $endpointType = ''; // soap|wsdl, empty for WSDL initialization error
var $persistentConnection = false;
var $defaultRpcParams = false; // This is no longer used
var $request = ''; // HTTP request
var $response = ''; // HTTP response
var $responseData = ''; // SOAP payload of response
var $cookies = array(); // Cookies from response or for request
var $decode_utf8 = true; // toggles whether the parser decodes element content w/ utf8_decode()
var $operations = array(); // WSDL operations, empty for WSDL initialization error
/**
* fault related variables
*
* @var fault
* @var faultcode
* @var faultstring
* @var faultdetail
* @access public
*/
var $fault, $faultcode, $faultstring, $faultdetail;
/**
* constructor
*
* @param mixed $endpoint SOAP server or WSDL URL (string), or wsdl instance (object)
* @param bool $wsdl optional, set to true if using WSDL
* @param int $portName optional portName in WSDL document
* @param string $proxyhost
* @param string $proxyport
* @param string $proxyusername
* @param string $proxypassword
* @param integer $timeout set the connection timeout
* @param integer $response_timeout set the response timeout
* @access public
*/
function soapclient($endpoint,$wsdl = false,$proxyhost = false,$proxyport = false,$proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30){
$this->endpoint = $endpoint;
$this->proxyhost = $proxyhost;
$this->proxyport = $proxyport;
$this->proxyusername = $proxyusername;
$this->proxypassword = $proxypassword;
$this->timeout = $timeout;
$this->response_timeout = $response_timeout;
// make values
if($wsdl){
if (is_object($endpoint) && is_a($endpoint, 'wsdl')) {
$this->wsdl = $endpoint;
$this->endpoint = $this->wsdl->wsdl;
$this->wsdlFile = $this->endpoint;
$this->debug('existing wsdl instance created from ' . $this->endpoint);
} else {
$this->wsdlFile = $this->endpoint;
// instantiate wsdl object and parse wsdl file
$this->debug('instantiating wsdl class with doc: '.$endpoint);
$this->wsdl =& wsdl($this->wsdlFile,$this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword,$this->timeout,$this->response_timeout);
}
$this->appendDebug($this->wsdl->getDebug());
$this->wsdl->clearDebug();
// 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);
$this->endpointType = 'wsdl';
} else {
$this->debug( 'getOperations returned false');
$this->setError('no operations defined in the WSDL document!');
}
} else {
$this->endpointType = 'soap';
}
}
/**
* calls method, returns PHP native type
*
* @param string $method SOAP server URL or path
* @param array $params An array, associative or simple, of the parameters
* for the method call, or a string that is the XML
* for the call. For rpc style, this call will
* wrap the XML in a tag named after the method, as
* well as the SOAP Envelope and Body. For document
* style, this will only wrap with the Envelope and Body.
* IMPORTANT: when using an array with document style,
* in which case there
* is really one parameter, the root of the fragment
* used in the call, which encloses what programmers
* normally think of parameters. A parameter array
* *must* include the wrapper.
* @param string $namespace optional method namespace (WSDL can override)
* @param string $soapAction optional SOAPAction value (WSDL can override)
* @param boolean $headers optional array of soapval objects for headers
* @param boolean $rpcParams optional (no longer used)
* @param string $style optional (rpc|document) the style to use when serializing parameters (WSDL can override)
* @param string $use optional (encoded|literal) the use when serializing parameters (WSDL can override)
* @return mixed
* @access public
*/
function call($operation,$params=array(),$namespace='http://tempuri.org',$soapAction='',$headers=false,$rpcParams=null,$style='rpc',$use='encoded'){
$this->operation = $operation;
$this->fault = false;
$this->setError('');
$this->request = '';
$this->response = '';
$this->responseData = '';
$this->faultstring = '';
$this->faultcode = '';
$this->opData = array();
$this->debug("call: $operation, $params, $namespace, $soapAction, $headers, $style, $use; endpointType: $this->endpointType");
if ($headers) {
$this->requestHeaders = $headers;
}
// serialize parameters
if($this->endpointType == 'wsdl' && $opData = $this->getOperationData($operation)){
// use WSDL for operation
$this->opData = $opData;
$this->debug("opData:");
$this->appendDebug($this->varDump($opData));
if (isset($opData['soapAction'])) {
$soapAction = $opData['soapAction'];
}
$this->endpoint = $opData['endpoint'];
$namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : $namespace;
$style = $opData['style'];
$use = $opData['input']['use'];
// add ns to ns array
if($namespace != '' && !isset($this->wsdl->namespaces[$namespace])){
$nsPrefix = 'ns' . rand(1000, 9999);
$this->wsdl->namespaces[$nsPrefix] = $namespace;
}
$nsPrefix = $this->wsdl->getPrefixFromNamespace($namespace);
// serialize payload
if (is_string($params)) {
$this->debug("serializing param string for WSDL operation $operation");
$payload = $params;
} elseif (is_array($params)) {
$this->debug("serializing param array for WSDL operation $operation");
$payload = $this->wsdl->serializeRPCParameters($operation,'input',$params);
} else {
$this->debug('params must be array or string');
$this->setError('params must be array or string');
return false;
}
$usedNamespaces = $this->wsdl->usedNamespaces;
// Partial fix for multiple encoding styles in the same function call
$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
if (isset($opData['output']['encodingStyle']) && $encodingStyle != $opData['output']['encodingStyle']) {
$methodEncodingStyle = ' SOAP-ENV:encodingStyle="' . $opData['output']['encodingStyle'] . '"';
} else {
$methodEncodingStyle = '';
}
$this->appendDebug($this->wsdl->getDebug());
$this->wsdl->clearDebug();
if ($errstr = $this->wsdl->getError()) {
$this->debug('got wsdl error: '.$errstr);
$this->setError('wsdl error: '.$errstr);
return false;
}
} elseif($this->endpointType == 'wsdl') {
// operation not in WSDL
$this->appendDebug($this->wsdl->getDebug());
$this->wsdl->clearDebug();
$this->setError( 'operation '.$operation.' not present.');
$this->debug("operation '$operation' not present.");
return false;
} else {
// no WSDL
//$this->namespaces['ns1'] = $namespace;
$nsPrefix = 'ns' . rand(1000, 9999);
// serialize
$payload = '';
if (is_string($params)) {
$this->debug("serializing param string for operation $operation");
$payload = $params;
} elseif (is_array($params)) {
$this->debug("serializing param array for operation $operation");
foreach($params as $k => $v){
$payload .= $this->serialize_val($v,$k,false,false,false,false,$use);
}
} else {
$this->debug('params must be array or string');
$this->setError('params must be array or string');
return false;
}
$usedNamespaces = array();
$methodEncodingStyle = '';
}
// wrap RPC calls with method element
if ($style == 'rpc') {
if ($use == 'literal') {
$this->debug("wrapping RPC request with literal method element");
if ($namespace) {
$payload = "<$operation xmlns=\"$namespace\">" . $payload . "$operation>";
} else {
$payload = "<$operation>" . $payload . "$operation>";
}
} else {
$this->debug("wrapping RPC request with encoded method element");
if ($namespace) {
$payload = "<$nsPrefix:$operation$methodEncodingStyle xmlns:$nsPrefix=\"$namespace\">" .
$payload .
"$nsPrefix:$operation>";
} else {
$payload = "<$operation$methodEncodingStyle>" .
$payload .
"$operation>";
}
}
}
// serialize envelope
$soapmsg = $this->serializeEnvelope($payload,$this->requestHeaders,$usedNamespaces,$style,$use);
$this->debug("endpoint: $this->endpoint, soapAction: $soapAction, namespace: $namespace, style: $style, use: $use");
$this->debug('SOAP message length: ' . strlen($soapmsg) . ' contents: ' . substr($soapmsg, 0, 1000));
// send
$return = $this->send($this->getHTTPBody($soapmsg),$soapAction,$this->timeout,$this->response_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: ');
$this->appendDebug($this->varDump($return));
// 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;
} elseif ($style == 'document') {
// NOTE: if the response is defined to have multiple parts (i.e. unwrapped),
// we are only going to return the first part here...sorry about that
return $return;
} else {
// array of return values
if(is_array($return)){
// multiple 'out' parameters, which we return wrapped up
// in the array
if(sizeof($return) > 1){
return $return;
}
// single 'out' parameter (normally the return value)
$return = array_shift($return);
$this->debug('return shifted value: ');
$this->appendDebug($this->varDump($return));
return $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];
}
$this->debug("No data for operation: $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 connection timeout in seconds
* @param integer $response_timeout set response timeout in seconds
* @return mixed native PHP types.
* @access private
*/
function send($msg, $soapaction = '', $timeout=0, $response_timeout=30) {
$this->checkCookies();
// detect transport
switch(true){
// http(s)
case ereg('^http',$this->endpoint):
$this->debug('transporting via HTTP');
if($this->persistentConnection == true && is_object($this->persistentConnection)){
$http =& $this->persistentConnection;
} else {
$http = new soap_transport_http($this->endpoint);
if ($this->persistentConnection) {
$http->usePersistentConnection();
}
}
$http->setContentType($this->getHTTPContentType(), $this->getHTTPContentTypeCharset());
$http->setSOAPAction($soapaction);
if($this->proxyhost && $this->proxyport){
$http->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword);
}
if($this->authtype != '') {
$http->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
}
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:')){
$this->responseData = $http->send($msg,$timeout,$response_timeout,$this->cookies);
} elseif(ereg('^https',$this->endpoint)){
//} elseif(strpos($this->endpoint,'https:')){
//if(phpversion() == '4.3.0-dev'){
//$response = $http->send($msg,$timeout,$response_timeout);
//$this->request = $http->outgoing_payload;
//$this->response = $http->incoming_payload;
//} else
$this->responseData = $http->sendHTTPS($msg,$timeout,$response_timeout,$this->cookies);
} else {
$this->setError('no http/s in endpoint url');
}
$this->request = $http->outgoing_payload;
$this->response = $http->incoming_payload;
$this->appendDebug($http->getDebug());
$this->UpdateCookies($http->incoming_cookies);
// save transport object if using persistent connections
if ($this->persistentConnection) {
$http->clearDebug();
if (!is_object($this->persistentConnection)) {
$this->persistentConnection = $http;
}
}
if($err = $http->getError()){
$this->setError('HTTP Error: '.$err);
return false;
} elseif($this->getError()){
return false;
} else {
$this->debug('got response, length: '. strlen($this->responseData).' type: '.$http->incoming_headers['content-type']);
return $this->parseResponse($http->incoming_headers, $this->responseData);
}
break;
default:
$this->setError('no transport found, or selected transport is not yet supported!');
return false;
break;
}
}
/**
* processes SOAP message returned from server
*
* @param array $headers The HTTP headers
* @param string $data unprocessed response data from server
* @return mixed value of the message, decoded into a PHP type
* @access protected
*/
function parseResponse($headers, $data) {
$this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' and type ' . $headers['content-type']);
if (!strstr($headers['content-type'], 'text/xml')) {
$this->setError('Response not of type text/xml');
return false;
}
if (strpos($headers['content-type'], '=')) {
$enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
$this->debug('Got response encoding: ' . $enc);
if(eregi('^(ISO-8859-1|US-ASCII|UTF-8)$',$enc)){
$this->xml_encoding = strtoupper($enc);
} else {
$this->xml_encoding = 'US-ASCII';
}
} else {
// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
$this->xml_encoding = 'ISO-8859-1';
}
$this->debug('Use encoding: ' . $this->xml_encoding . ' when creating soap_parser');
$parser = new soap_parser($data,$this->xml_encoding,$this->operation,$this->decode_utf8);
// add parser debug data to our debug
$this->appendDebug($parser->getDebug());
// 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 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 string
* @access public
*/
function getHeaders(){
return $this->responseHeaders;
}
/**
* set proxy info here
*
* @param string $proxyhost
* @param string $proxyport
* @param string $proxyusername
* @param string $proxypassword
* @access public
*/
function setHTTPProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '') {
$this->proxyhost = $proxyhost;
$this->proxyport = $proxyport;
$this->proxyusername = $proxyusername;
$this->proxypassword = $proxypassword;
}
/**
* if authenticating, set user credentials here
*
* @param string $username
* @param string $password
* @param string $authtype (basic|digest|certificate)
* @param array $certRequest (keys must be cainfofile, sslcertfile, sslkeyfile, passphrase: see corresponding options in cURL docs)
* @access public
*/
function setCredentials($username, $password, $authtype = 'basic', $certRequest = array()) {
$this->username = $username;
$this->password = $password;
$this->authtype = $authtype;
$this->certRequest = $certRequest;
}
/**
* use HTTP encoding
*
* @param string $enc
* @access public
*/
function setHTTPEncoding($enc='gzip, deflate'){
$this->http_encoding = $enc;
}
/**
* use HTTP persistent connections if possible
*
* @access public
*/
function useHTTPPersistentConnection(){
$this->persistentConnection = true;
}
/**
* gets the default RPC parameter setting.
* If true, default is that call params are like RPC even for document style.
* Each call() can override this value.
*
* This is no longer used.
*
* @access public
* @deprecated
*/
function getDefaultRpcParams() {
return $this->defaultRpcParams;
}
/**
* sets the default RPC parameter setting.
* If true, default is that call params are like RPC even for document style
* Each call() can override this value.
*
* This is no longer used.
*
* @param boolean $rpcParams
* @access public
* @deprecated
*/
function setDefaultRpcParams($rpcParams) {
$this->defaultRpcParams = $rpcParams;
}
/**
* dynamically creates proxy class, allowing user to directly call methods from wsdl
*
* @return object soap_proxy object
* @access public
*/
function getProxy(){
if ($this->endpointType != 'wsdl') {
$this->setError('The getProxy method only works for a WSDL client');
return null;
}
$evalStr = '';
foreach($this->operations as $operation => $opData){
if($operation != ''){
// create param string
$paramStr = '';
if(sizeof($opData['input']['parts']) > 0){
foreach($opData['input']['parts'] as $name => $type){
$paramStr .= "\$$name,";
}
$paramStr = substr($paramStr,0,strlen($paramStr)-1);
}
$opData['namespace'] = !isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace'];
$evalStr .= "function " . str_replace('.', '__', $operation) . " ($paramStr) {
// load params into array
\$params = array($paramStr);
return \$this->call('$operation',\$params,'".$opData['namespace']."','".(isset($opData['soapAction']) ? $opData['soapAction'] : '')."');
}";
unset($paramStr);
}
}
$r = rand();
$evalStr = 'class soap_proxy_'.$r.' extends soapclient {
'.$evalStr.'
}';
//print "proxy class:
$evalStr
";
// eval the class
eval($evalStr);
// instantiate proxy object
eval("\$proxy = new soap_proxy_$r('');");
// 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;
$proxy->defaultRpcParams = $this->defaultRpcParams;
// transfer other state
$proxy->username = $this->username;
$proxy->password = $this->password;
$proxy->authtype = $this->authtype;
$proxy->proxyhost = $this->proxyhost;
$proxy->proxyport = $this->proxyport;
$proxy->proxyusername = $this->proxyusername;
$proxy->proxypassword = $this->proxypassword;
$proxy->timeout = $this->timeout;
$proxy->response_timeout = $this->response_timeout;
$proxy->http_encoding = $this->http_encoding;
$proxy->persistentConnection = $this->persistentConnection;
$proxy->requestHeaders = $this->requestHeaders;
$proxy->soap_defencoding = $this->soap_defencoding;
return $proxy;
}
/**
* gets the HTTP body for the current request.
*
* @param string $soapmsg The SOAP payload
* @return string The HTTP body, which includes the SOAP payload
* @access protected
*/
function getHTTPBody($soapmsg) {
return $soapmsg;
}
/**
* gets the HTTP content type for the current request.
*
* Note: getHTTPBody must be called before this.
*
* @return string the HTTP content type for the current request.
* @access protected
*/
function getHTTPContentType() {
return 'text/xml';
}
/**
* gets the HTTP content type charset for the current request.
* returns false for non-text content types.
*
* Note: getHTTPBody must be called before this.
*
* @return string the HTTP content type charset for the current request.
* @access protected
*/
function getHTTPContentTypeCharset() {
return $this->soap_defencoding;
}
/*
* whether or not parser should decode utf8 element content
*
* @return always returns true
* @access public
*/
function decodeUTF8($bool){
$this->decode_utf8 = $bool;
return true;
}
/**
* adds a new Cookie into $this->cookies array
*
* @param string $name Cookie Name
* @param string $value Cookie Value
* @return if cookie-set was successful returns true, else false
* @access public
*/
function setCookie($name, $value) {
if (strlen($name) == 0) {
return false;
}
$this->cookies[] = array('name' => $name, 'value' => $value);
return true;
}
/**
* gets all Cookies
*
* @return array with all internal cookies
* @access public
*/
function getCookies() {
return $this->cookies;
}
/**
* checks all Cookies and delete those which are expired
*
* @return always return true
* @access public
*/
function checkCookies() {
if (sizeof($this->cookies) == 0) {
return true;
}
$this->debug('checkCookie: check ' . sizeof($this->cookies) . ' cookies');
$curr_cookies = $this->cookies;
$this->cookies = array();
foreach ($curr_cookies as $cookie) {
if (! is_array($cookie)) {
$this->debug('Remove cookie that is not an array');
continue;
}
if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) {
if (strtotime($cookie['expires']) > time()) {
$this->cookies[] = $cookie;
} else {
$this->debug('Remove expired cookie ' . $cookie['name']);
}
} else {
$this->cookies[] = $cookie;
}
}
$this->debug('checkCookie: '.sizeof($this->cookies).' cookies left in array');
return true;
}
/**
* updates the current cookies with a new set
*
* @param array $cookies new cookies with which to update current ones
* @return always return true
* @access public
*/
function UpdateCookies($cookies) {
if (sizeof($this->cookies) == 0) {
// no existing cookies: take whatever is new
if (sizeof($cookies) > 0) {
$this->debug('Setting new cookie(s)');
$this->cookies = $cookies;
}
return true;
}
if (sizeof($cookies) == 0) {
// no new cookies: keep what we've got
return true;
}
// merge
foreach ($cookies as $newCookie) {
if (!is_array($newCookie)) {
continue;
}
if ((!isset($newCookie['name'])) || (!isset($newCookie['value']))) {
continue;
}
$newName = $newCookie['name'];
$found = false;
for ($i = 0; $i < count($this->cookies); $i++) {
$cookie = $this->cookies[$i];
if (!is_array($cookie)) {
continue;
}
if (!isset($cookie['name'])) {
continue;
}
if ($newName != $cookie['name']) {
continue;
}
$newDomain = isset($newCookie['domain']) ? $newCookie['domain'] : 'NODOMAIN';
$domain = isset($cookie['domain']) ? $cookie['domain'] : 'NODOMAIN';
if ($newDomain != $domain) {
continue;
}
$newPath = isset($newCookie['path']) ? $newCookie['path'] : 'NOPATH';
$path = isset($cookie['path']) ? $cookie['path'] : 'NOPATH';
if ($newPath != $path) {
continue;
}
$this->cookies[$i] = $newCookie;
$found = true;
$this->debug('Update cookie ' . $newName . '=' . $newCookie['value']);
break;
}
if (! $found) {
$this->debug('Add cookie ' . $newName . '=' . $newCookie['value']);
$this->cookies[] = $newCookie;
}
}
return true;
}
}
?>