SOAP_Interop
[ class tree: SOAP_Interop ] [ index: SOAP_Interop ] [ all elements ]

Source for file interop_test_functions.php

Documentation is available at interop_test_functions.php

  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.         $dt =new SOAP_Type_dateTime();
  39.         $ok $dt->compare($e1$e2== 0;
  40.     }
  41.     return $ok || $e1 == $e2 || strcasecmp(trim($e1)trim($e2)) == 0;
  42. }
  43.  
  44. function array_compare(&$ar1&$ar2)
  45. {
  46.     if (gettype($ar1!= 'array' || gettype($ar2!= 'array'return FALSE;
  47.     # first a shallow diff
  48.     if (count($ar1!= count($ar2)) return FALSE;
  49.     $diff array_diff($ar1$ar2);
  50.     if (count($diff== 0return TRUE;
  51.  
  52.     # diff failed, do a full check of the array
  53.     foreach ($ar1 as $k => $v{
  54.         #print "comparing $v == $ar2[$k]\n";
  55.         if (gettype($v== "array"{
  56.             if (!array_compare($v$ar2[$k])) return FALSE;
  57.         else {
  58.             if (!string_compare($v$ar2[$k])) return FALSE;
  59.             if ($type == 'float')
  60.                 # we'll only compare to 3 digits of precision
  61.                 $ok number_compare($expect$result,3);
  62.             if ($type == 'boolean')
  63.                 $ok boolean_compare($expect$result);
  64.             else
  65.                 $ok string_compare($expect$result);
  66.         }
  67.     }
  68.     return TRUE;
  69. }
  70.  
  71.  
  72. function &parseMessage($msg)
  73. {
  74.     # strip line endings
  75.     #$msg = preg_replace('/\r|\n/', ' ', $msg);
  76.     $response =new SOAP_Parser($msg);
  77.     if ($response->fault{
  78.         return $response->fault->getFault();
  79.     }
  80.     $return =$response->getResponse();
  81.     $v =$response->decode($return);
  82.     if (gettype($v== 'array' && count($v)==1{
  83.         return array_shift($v);
  84.     }
  85.     return $v;
  86. }
  87.  
  88.  
  89. ?>

Documentation generated on Mon, 11 Mar 2019 14:54:33 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.