Esempio n. 1
0
 /**
  * Takes all parts of the given type and appends its fields to the given name.
  * This happend recursively down to builtin types.
  * Example:
  * $name = point
  * $type = Point (with the fields x and y)
  * result:
  *    - point.x
  *    - point.y
  *
  * @param string $name
  * 		The fields of the type are added to this name, separated by a dot.
  * @param string $type
  * 		The name of an XSD base type or a type defined in the WSDL.
  * @param SoapClient $wsClient
  *
  * @param array<string> $typePath
  * 		This array contains all types that were encountered in the recursion.
  * 		To avoid an inifinite loop, the recursion stops if $type is already
  * 		in the $typePath. This parameter is omitted in the top level call.
  * @return array<string>
  * 		All resulting paths. If a path causes an endless recursion, the
  * 		keyword ##overflow## is appended to the path.
  */
 public static function flattenParam($name, $type, $wsClient, &$typePath = null)
 {
     //I made this method public and static and also
     //added the parameter $wsClient so that it is accessible
     //via the ajax interface
     //add initial xpath root
     if (strpos($name, "/") === false) {
         $name = "//" . $name;
     }
     $flatParams = array();
     if (!$wsClient->isCustomType($type) && substr($type, 0, 7) != "ArrayOf") {
         // $type is a simple type
         $flatParams[] = $name;
         return $flatParams;
     }
     if (substr($type, 0, 7) == "ArrayOf") {
         if ($wsClient->isCustomType(substr($type, 7))) {
             //$flatParams[] = $name."[*]";
             $flatParams[] = $name;
             return $flatParams;
         }
     }
     $tp = $wsClient->getTypeDefinition($type);
     foreach ($tp as $var => $type) {
         if (substr($type, 0, 7) == "ArrayOf") {
             $type = substr($type, 7);
             //$fname = ($name == "//") ? "//".$var."[*]" : $name.'/'.$var."[*]";
             $fname = $name == "//" ? "//" . $var : $name . '/' . $var;
         } else {
             $fname = $name == "//" ? "//" . $var : $name . '/' . $var;
         }
         if ($wsClient->isCustomType($type)) {
             if (!$typePath) {
                 $typePath = array();
             }
             if (in_array($type, $typePath)) {
                 // stop recursion
                 $flatParams[] = $fname . "##overflow##";
                 continue;
             }
             $typePath[] = $type;
             $names = WebService::flattenParam($fname, $type, $wsClient, $typePath);
             $flatParams = array_merge($flatParams, $names);
             array_pop($typePath);
         } else {
             $flatParams[] = $fname;
         }
     }
     return $flatParams;
 }
 private function getMergedParameters($wwsd, $result)
 {
     $wsClient = DefineWebServiceSpecialAjaxAccess::createWSClient($wwsd->getURI());
     if ($result) {
         $wwsdParameters = new SimpleXMLElement($wwsd->getResult());
     } else {
         $wwsdParameters = new SimpleXMLElement("<p>" . $wwsd->getParameters() . "</p>");
     }
     $wwsdParameters = $wwsdParameters->children();
     $rawParameters = $wsClient->getOperation($wwsd->getMethod());
     $wsdlParameters = array();
     if ($result) {
         $wsdlParameters = WebService::flattenParam("", $rawParameters[0], $wsClient);
     } else {
         //todo: handle no params
         $numParam = count($rawParameters);
         for ($i = 1; $i < $numParam; $i++) {
             $pName = $rawParameters[$i][0];
             $pType = $rawParameters[$i][1];
             $tempFlat = WebService::flattenParam($pName, $pType, $wsClient);
             $wsdlParameters = array_merge($wsdlParameters, $tempFlat);
         }
     }
     $mergedParameters = array();
     $unsetwwsdParameters = array();
     //todo: handle overflows
     foreach ($wsdlParameters as $wsdlParameter) {
         if (!$result) {
             $wsdlParameter = substr($wsdlParameter, 1);
         }
         $wsdlParameterSteps = explode("/", $wsdlParameter);
         $found = false;
         foreach ($wwsdParameters as $key => $wwsdParameter) {
             if (!is_null($wwsdParameter['subject'])) {
                 continue;
             }
             if (!$result) {
                 $matchedPath = "/";
             } else {
                 $matchedPath = "//";
             }
             $wwsdParameterSteps = explode("/", $wwsdParameter["path"]);
             if (count($wsdlParameterSteps) != count($wwsdParameterSteps)) {
                 continue;
             }
             for ($k = 0; $k < count($wsdlParameterSteps); $k++) {
                 if ($wsdlParameterSteps[$k] == "" && $wwsdParameterSteps[$k] == "") {
                     continue;
                 }
                 $dupPos = strpos($wsdlParameterSteps[$k], "##duplicate");
                 $overflowPos = strpos($wsdlParameterSteps[$k], "##overflow");
                 //$bracketPos = strpos($wwsdParameterSteps[$k], "[");
                 $wwsdParameterStep = $wwsdParameterSteps[$k];
                 //if($bracketPos > 0){
                 //	$wwsdParameterStep = substr($wwsdParameterStep, 0, $bracketPos);
                 //	$dupPos = $dupPos."-";
                 //}
                 if (@strpos($wsdlParameterSteps[$k], $wwsdParameterStep) === 0) {
                     $matchedPath .= "/" . $wwsdParameterSteps[$k];
                     if ($overflowPos) {
                         $matchedPath .= "##overflow##";
                     }
                     if ($dupPos) {
                         $matchedPath .= "##duplicate";
                     }
                 } else {
                     $matchedPath = "";
                     break;
                 }
             }
             if (strlen($matchedPath) > 0 && $matchedPath != "//") {
                 $found = true;
                 $a = array();
                 $a["name"] = $wwsdParameter["name"] . "";
                 $a["path"] = substr($matchedPath, 1);
                 if (!$result) {
                     $a["defaultValue"] = $wwsdParameter["defaultValue"] . "";
                     $a["optional"] = $wwsdParameter["optional"] . "";
                     if (strlen($a["optional"] . "") == 0) {
                         $a["optional"] = "##";
                     }
                     if (strlen($a["defaultValue"] . "") == 0) {
                         $a["defaultValue"] = "##";
                     }
                     $subParameter = $this->getSubParameter($wwsdParameter);
                     if (strlen($subParameter) > 0) {
                         $a["subParameter"] = $subParameter;
                     } else {
                         $a["subParameter"] = "##";
                     }
                     $mergedParameters[$a["path"]] = $a;
                 } else {
                     $a["xpath"] = $wwsdParameter["xpath"] . "";
                     $a["json"] = $wwsdParameter["json"] . "";
                     if (strlen($a["xpath"] . "") > 0 || strlen($a["json"] . "") > 0) {
                         if (!array_key_exists($a["path"] . "####", $mergedParameters)) {
                             $found = false;
                         }
                     }
                     if (strlen($a["xpath"] . "") == 0) {
                         $a["xpath"] = "##";
                     }
                     if (strlen($a["json"] . "") == 0) {
                         $a["json"] = "##";
                     }
                     $mergedParameters[$a["path"] . $a["json"] . $a["xpath"]] = $a;
                 }
                 $unsetwwsdParameters[$wwsdParameter["path"] . ""] = true;
                 continue;
             }
         }
         if (!$found) {
             $a = array();
             $a["path"] = $wsdlParameter;
             $a["name"] = "##";
             if (!$result) {
                 $a["optional"] = "##";
                 $a["defaultValue"] = "##";
                 $a["subParameter"] = "##";
                 $mergedParameters[$a["path"]] = $a;
             } else {
                 $a["xpath"] = "##";
                 $a["json"] = "##";
                 $mergedParameters[$a["path"] . $a["json"] . $a["xpath"]] = $a;
             }
         }
     }
     foreach ($wwsdParameters as $wsParameter) {
         //do not deal with triplification instruction
         if (!is_null($wwsdParameter['subject'])) {
             continue;
         }
         if (!array_key_exists($wsParameter["path"] . "", $unsetwwsdParameters)) {
             $o = array();
             $o["name"] = $wsParameter["name"] . "";
             if ($result) {
                 $o["path"] = "##unmatched" . $wsParameter["path"] . "";
             } else {
                 $o["path"] = $wsParameter["path"] . "";
             }
             if (!$result) {
                 $o["defaultValue"] = $wsParameter["defaultValue"] . "";
                 $o["optional"] = $wsParameter["optional"] . "";
                 if (strlen($o["optional"] . "") == 0) {
                     $o["optional"] = "##";
                 }
                 if (strlen($o["defaultValue"] . "") == 0) {
                     $o["defaultValue"] = "##";
                 }
                 $subParameter = $this->getSubParameter($wsParameter);
                 if (strlen($subParameter) > 0) {
                     $a["subParameter"] = $subParameter;
                 } else {
                     $a["subParameter"] = "##";
                 }
                 $mergedParameters[$o["path"]] = $o;
             } else {
                 $o["json"] = $wsParameter["json"] . "";
                 $o["xpath"] = $wsParameter["xpath"] . "";
                 if (strlen($o["json"] . "") == 0) {
                     $o["json"] = "##";
                 }
                 if (strlen($o["xpath"] . "") == 0) {
                     $o["xpath"] = "##";
                 }
                 $mergedParameters[$o["path"] . $o["json"] . $o["xpath"]] = $o;
             }
         }
     }
     ksort($mergedParameters);
     $html = "";
     if ($result) {
         $html .= "<span id=\"editresults\" style=\"display: none\">";
     } else {
         $html .= "<span id=\"editparameters\" style=\"display: none\">";
     }
     $html .= "soap;";
     foreach ($mergedParameters as $mergedParameter) {
         $html .= $mergedParameter["name"] . ";";
         // remove parameter paths that start with "//"
         $html .= $mergedParameter["path"] . ";";
         if (!$result) {
             if (array_key_exists("optional", $mergedParameter)) {
                 $html .= $mergedParameter["optional"] . ";";
             } else {
                 $html .= "##;";
             }
             if (array_key_exists("defaultValue", $mergedParameter)) {
                 $html .= $mergedParameter["defaultValue"] . ";";
             } else {
                 $html .= "##;";
             }
             if (array_key_exists("subParameter", $mergedParameter)) {
                 $html .= $mergedParameter["subParameter"] . ";";
             } else {
                 $html .= "##;";
             }
         } else {
             $html .= $mergedParameter["xpath"] . ";";
             $html .= $mergedParameter["json"] . ";";
         }
     }
     $html .= "</span>";
     return $html;
 }
/**
 * this method is called after step 3 (specify parameters)
 *
 * @param unknown_string $uri uri of the wsdl
 * @param unknown_string $methodName the method which was chosen by the user
 * @return string ";"-separated list of return types that have to be specified
 * 			for this method
 */
function smwf_ws_processStep3($uri, $authenticationType, $user, $pw, $methodName)
{
    $wsClient = DefineWebServiceSpecialAjaxAccess::createWSClient($uri, $authenticationType, $user, $pw);
    $rawResult = $wsClient->getOperation($methodName);
    $flatResult = WebService::flattenParam("", $rawResult[0], $wsClient, $typePath);
    return "todo:handle exceptions;" . implode(";", $flatResult);
}