function string_compare($e1, $e2) { if (!is_string($e1) || !is_string($e2)) { return false; } $e1 = trim(str_replace(array("\r", "\n"), '', $e1)); $e2 = trim(str_replace(array("\r", "\n"), '', $e2)); if (is_numeric($e1) && is_numeric($e2)) { return number_compare($e1, $e2); } // handle dateTime comparison $e1_type = gettype($e1); $e2_type = gettype($e2); $ok = false; if ($e1_type == "string") { require_once 'SOAP/Type/dateTime.php'; $dt = new SOAP_Type_dateTime(); $ok = $dt->compare($e1, $e2) == 0; } return $ok || $e1 == $e2 || strcasecmp($e1, $e2) == 0; }
/** * SOAP::Value::_getType * * Convert a php type to a soap type. * * @param string &$value The value to inspect. * * @return string Soap type. * * @access private */ function _getType(&$value) { global $SOAP_OBJECT_STRUCT, $SOAP_RAW_CONVERT; $type = gettype($value); switch ($type) { case 'object': if (is_a($value, 'soap_value')) { $type = $value->type; } else { $type = 'Struct'; } break; case 'array': // XXX hashes always get done as structs by pear::soap if ($this->_isHash($value)) { $type = 'Struct'; } else { $ar_size = count($value); reset($value); $key1 = key($value); if ($ar_size > 0 && is_a($key1, 'soap_value')) { // fixme for non-wsdl structs that are all the same type $key2 = key($value); if ($ar_size > 1 && $this->_isSoapValue($key1) && $this->_isSoapValue($key2) && $key1->name != $key2->name) { // this is a struct, not an array $type = 'Struct'; } else { $type = 'Array'; } } else { $type = 'Array'; } } break; case 'integer': case 'long': $type = 'int'; break; case 'boolean': break; case 'double': $type = 'float'; // double is deprecated in 4.2 and later break; case 'null': $type = ''; break; case 'string': if ($SOAP_RAW_CONVERT) { if (is_numeric($value)) { if (strstr($value, '.')) { $type = 'float'; } else { $type = 'int'; } } else { if (SOAP_Type_hexBinary::is_hexbin($value)) { $type = 'hexBinary'; } else { if ($this->_isBase64($value)) { $type = 'base64Binary'; } else { $dt = new SOAP_Type_dateTime($value); if ($dt->toUnixtime() != -1) { $type = 'dateTime'; } } } } } break; default: break; } return $type; }
function echoDate($timeInstant) { require_once 'SOAP/Type/dateTime.php'; $dt = new SOAP_Type_dateTime($timeInstant); if ($dt->toUnixtime() != -1) { $value = $dt->toSOAP(); return new SOAP_Value('return', 'dateTime', $value); } else { return new SOAP_Fault("Value $timeInstant is not a dateTime value"); } }
/** * SOAP::Value::_getSoapType * * convert php type to soap type * @param string value * @param string type - presumed php type * * @return string type - soap type * @access private */ function _getSoapType(&$value, &$type) { $doconvert = FALSE; if (0 && $this->wsdl) { # see if it's a complex type so we can deal properly with SOAPENC:arrayType if (!$type && $this->name) { # XXX TODO: # look up the name in the wsdl and validate the type $this->debug("SOAP_VALUE no type for {$this->name}!"); } else { if ($type) { # XXX TODO: # this code currently handles only one way of encoding array types in wsdl # need to do a generalized function to figure out complex types if (array_key_exists($type, $this->wsdl->complexTypes)) { if ($this->arrayType = $this->wsdl->complexTypes[$type]['arrayType']) { $type = 'Array'; } else { if ($this->wsdl->complexTypes[$type]['order'] == 'sequence' && array_key_exists('elements', $this->wsdl->complexTypes[$type])) { reset($this->wsdl->complexTypes[$type]['elements']); # assume an array if (count($this->wsdl->complexTypes[$type]['elements']) == 1) { $arg = current($this->wsdl->complexTypes[$type]['elements']); $this->arrayType = $arg['type']; $type = 'Array'; } else { foreach ($this->wsdl->complexTypes[$type]['elements'] as $element) { if ($element['name'] == $type) { $this->arrayType = $element['type']; $type = $element['type']; } } } } } } } } } if (!$type || !$this->verifyType($type)) { if ($type && $this->wsdl && array_key_exists($type, $this->wsdl->complexTypes)) { # do nothing, this preserves our complex types } else { if (is_object($value)) { # allows for creating special classes to handle soap types $type = get_class($value); # this may return a different type that we process below $value = $value->toSOAP(); } elseif (isArray($value)) { $type = isHash($value) ? 'Struct' : 'Array'; } elseif (isInt($value)) { $type = 'int'; } elseif (isFloat($value)) { $type = 'float'; } elseif (SOAP_Type_hexBinary::is_hexbin($value)) { $type = 'hexBinary'; } elseif (isBase64($value)) { $type = 'base64Binary'; } elseif (isBoolean($value)) { $type = 'boolean'; } else { $type = gettype($value); # php defaults a lot of stuff to string, if we have no # idea what the type realy is, we have to try to figure it out # this is the best we can do if the user did not use the SOAP_Value class if ($type == 'string') { $doconvert = TRUE; } } } } # we have the type, handle any value munging we need if ($doconvert) { $dt = new SOAP_Type_dateTime($value); if ($dt->toUnixtime() != -1) { $type = 'dateTime'; $value = $dt->toSOAP(); } } else { if ($type == 'dateTime') { # encode a dateTime to ISOE $dt = new SOAP_Type_dateTime($value); $value = $dt->toSOAP(); } else { // php type name mangle if ($type == 'integer') { $type = 'int'; } else { if ($type == 'boolean') { if ($value != 0 && $value != '0' || strcasecmp($value, 'true') == 0) { $value = 'true'; } else { $value = 'false'; } } } } } return $type; }