home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / SOAP / Interop / interop_test_functions.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  2.6 KB  |  90 lines

  1. <?php
  2. require_once("SOAP/Parser.php");
  3. require_once("SOAP/Value.php");
  4.  
  5. function number_compare($f1, $f2)
  6. {
  7.     # figure out which has the least fractional digits
  8.     preg_match('/.*?\.(.*)/',$f1,$m1);
  9.     preg_match('/.*?\.(.*)/',$f2,$m2);
  10.     #print_r($m1);
  11.     # always use at least 2 digits of precision
  12.     $d = max(min(strlen(count($m1)?$m1[1]:'0'),strlen(count($m2)?$m2[1]:'0')),2);
  13.     if ($d > 3) $d = 3;
  14.     $f1 = round($f1, $d);
  15.     $f2 = round($f2, $d);
  16.     return bccomp($f1, $f2, $d) == 0;
  17. }
  18.  
  19. function boolean_compare($f1, $f2)
  20. {
  21.     if (($f1 == 'true' || $f1 === TRUE || $f1 != 0) &&
  22.         ($f2 == 'true' || $f2 === TRUE || $f2 != 0)) return TRUE;
  23.     if (($f1 == 'false' || $f1 === FALSE || $f1 == 0) &&
  24.         ($f2 == 'false' || $f2 === FALSE || $f2 == 0)) return TRUE;
  25.     return FALSE;
  26. }
  27.  
  28. function string_compare($e1, $e2)
  29. {
  30.     if (is_numeric($e1) && is_numeric($e2)) {
  31.         return number_compare($e1, $e2);
  32.     }
  33.     # handle dateTime comparison
  34.     $e1_type = gettype($e1);
  35.     $e2_type = gettype($e2);
  36.     $ok = FALSE;
  37.     if ($e1_type == "string") {
  38.         require_once 'SOAP/Type/dateTime.php';
  39.         $dt =& new SOAP_Type_dateTime();
  40.         $ok = $dt->compare($e1, $e2) == 0;
  41.     }
  42.     return $ok || $e1 == $e2 || strcasecmp(trim($e1), trim($e2)) == 0;
  43. }
  44.  
  45. function array_compare(&$ar1, &$ar2)
  46. {
  47.     if (gettype($ar1) != 'array' || gettype($ar2) != 'array') return FALSE;
  48.     # first a shallow diff
  49.     if (count($ar1) != count($ar2)) return FALSE;
  50.     $diff = array_diff($ar1, $ar2);
  51.     if (count($diff) == 0) return TRUE;
  52.  
  53.     # diff failed, do a full check of the array
  54.     foreach ($ar1 as $k => $v) {
  55.         #print "comparing $v == $ar2[$k]\n";
  56.         if (gettype($v) == "array") {
  57.             if (!array_compare($v, $ar2[$k])) return FALSE;
  58.         } else {
  59.             if (!string_compare($v, $ar2[$k])) return FALSE;
  60.             if ($type == 'float')
  61.                 # we'll only compare to 3 digits of precision
  62.                 $ok = number_compare($expect, $result,3);
  63.             if ($type == 'boolean')
  64.                 $ok = boolean_compare($expect, $result);
  65.             else
  66.                 $ok = string_compare($expect, $result);
  67.         }
  68.     }
  69.     return TRUE;
  70. }
  71.  
  72.  
  73. function &parseMessage($msg)
  74. {
  75.     # strip line endings
  76.     #$msg = preg_replace('/\r|\n/', ' ', $msg);
  77.     $response =& new SOAP_Parser($msg);
  78.     if ($response->fault) {
  79.         return $response->fault->getFault();
  80.     }
  81.     $return =& $response->getResponse();
  82.     $v =& $response->decode($return);
  83.     if (gettype($v) == 'array' && count($v)==1) {
  84.         return array_shift($v);
  85.     }
  86.     return $v;
  87. }
  88.  
  89.  
  90. ?>