Changeset 21304 for branches/version-2_11-dev/data/module/SOAP/WSDL.php
- Timestamp:
- 2011/10/31 13:54:41 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_11-dev/data/module/SOAP/WSDL.php
r21299 r21304 25 25 require_once 'SOAP/Base.php'; 26 26 require_once 'SOAP/Fault.php'; 27 require_once ' HTTP/Request.php';27 require_once 'Request.php'; 28 28 29 29 define('WSDL_CACHE_MAX_AGE', 43200); … … 37 37 * 38 38 * @todo 39 * - add wsdl caching 39 40 * - refactor namespace handling ($namespace/$ns) 40 41 * - implement IDL type syntax declaration so we can generate WSDL … … 230 231 * service. 231 232 */ 232 function parseObject( $wsdl_obj, $targetNamespace, $service_name,233 function parseObject(&$wsdl_obj, $targetNamespace, $service_name, 233 234 $service_desc = '') 234 235 { 235 $parser = new SOAP_WSDL_ObjectParser($wsdl_obj, $this,236 $targetNamespace, $service_name,237 $service_desc);238 239 if ($parser->fault) {240 $this->_raiseSoapFault($parser->fault);241 }236 $parser =& new SOAP_WSDL_ObjectParser($wsdl_obj, $this, 237 $targetNamespace, $service_name, 238 $service_desc); 239 240 if ($parser->fault) { 241 $this->_raiseSoapFault($parser->fault); 242 } 242 243 } 243 244 … … 313 314 $opData = $this->bindings[$binding]['operations'][$operation]; 314 315 } 315 // Get operation data from porttype.316 // get operation data from porttype 316 317 $portType = $this->bindings[$binding]['type']; 317 318 if (!$portType) { … … 405 406 } 406 407 407 if (!isset($this->ns[$namespace])) { 408 return null; 409 } 410 411 $nsp = $this->ns[$namespace]; 412 //if (!isset($this->elements[$nsp])) 413 // $nsp = $this->namespaces[$nsp]; 414 if (!isset($this->elements[$nsp][$datatype])) { 415 return null; 416 } 417 418 $checkmessages = array(); 419 // Find what messages use this datatype. 420 foreach ($this->messages as $messagename => $message) { 421 foreach ($message as $part) { 422 if ($part['type'] == $datatype) { 423 $checkmessages[] = $messagename; 424 break; 425 } 426 } 427 } 428 // Find the operation that uses this message. 429 foreach($this->portTypes as $porttype) { 430 foreach ($porttype as $opname => $opinfo) { 431 foreach ($checkmessages as $messagename) { 432 if ($opinfo['input']['message'] == $messagename) { 433 return $opname; 408 if (isset($this->ns[$namespace])) { 409 $nsp = $this->ns[$namespace]; 410 //if (!isset($this->elements[$nsp])) 411 // $nsp = $this->namespaces[$nsp]; 412 if (isset($this->elements[$nsp][$datatype])) { 413 $checkmessages = array(); 414 // Find what messages use this datatype. 415 foreach ($this->messages as $messagename => $message) { 416 foreach ($message as $part) { 417 if ($part['type'] == $datatype) { 418 $checkmessages[] = $messagename; 419 break; 420 } 421 } 422 } 423 // Find the operation that uses this message. 424 foreach($this->portTypes as $porttype) { 425 foreach ($porttype as $opname => $opinfo) { 426 foreach ($checkmessages as $messagename) { 427 if ($opinfo['input']['message'] == $messagename) { 428 return $opname; 429 } 430 } 434 431 } 435 432 } … … 854 851 } 855 852 856 /** 857 * @param QName $name A parameter name. 858 * @param QName $type A parameter type. 859 * 860 * @return array A list of [type, array element type, array element 861 * namespace, array length]. 862 */ 863 function getSchemaType($type, $name) 853 function getSchemaType($type, $name, $type_namespace) 864 854 { 865 855 // see if it's a complex type so we can deal properly with … … 869 859 // look up the name in the wsdl and validate the type. 870 860 foreach ($this->complexTypes as $types) { 871 if (isset($types[$type ->name])) {872 if (isset($types[$type ->name]['type'])) {873 list($arraytype_ns, $arraytype, $array_depth) = isset($types[$type ->name]['arrayType'])874 ? $this->_getDeepestArrayType($types[$type ->name]['namespace'], $types[$type->name]['arrayType'])875 : array($this->namespaces[$types[$type ->name]['namespace']], null, 0);876 return array($types[$type ->name]['type'], $arraytype, $arraytype_ns, $array_depth);877 } 878 if (isset($types[$type ->name]['arrayType'])) {861 if (isset($types[$type])) { 862 if (isset($types[$type]['type'])) { 863 list($arraytype_ns, $arraytype, $array_depth) = isset($types[$type]['arrayType']) 864 ? $this->_getDeepestArrayType($types[$type]['namespace'], $types[$type]['arrayType']) 865 : array($this->namespaces[$types[$type]['namespace']], null, 0); 866 return array($types[$type]['type'], $arraytype, $arraytype_ns, $array_depth); 867 } 868 if (isset($types[$type]['arrayType'])) { 879 869 list($arraytype_ns, $arraytype, $array_depth) = 880 $this->_getDeepestArrayType($types[$type ->name]['namespace'], $types[$type->name]['arrayType']);870 $this->_getDeepestArrayType($types[$type]['namespace'], $types[$type]['arrayType']); 881 871 return array('Array', $arraytype, $arraytype_ns, $array_depth); 882 872 } 883 if (!empty($types[$type ->name]['elements'][$name->name])) {884 $type ->name = $types[$type->name]['elements']['type'];885 return array($type ->name, null, $this->namespaces[$types[$type->name]['namespace']], null);886 } 887 break; 888 } 889 } 890 } 891 if ($type && $type ->namespace) {873 if (!empty($types[$type]['elements'][$name])) { 874 $type = $types[$type]['elements']['type']; 875 return array($type, null, $this->namespaces[$types[$type]['namespace']], null); 876 } 877 break; 878 } 879 } 880 } 881 if ($type && $type_namespace) { 892 882 $arrayType = null; 893 883 // XXX TODO: … … 895 885 // types in wsdl need to do a generalized function to figure out 896 886 // complex types 897 $p = $this->ns[$type ->namespace];898 if ($p && !empty($this->complexTypes[$p][$type ->name])) {899 if ($arrayType = $this->complexTypes[$p][$type ->name]['arrayType']) {900 $type ->name= 'Array';901 } elseif ($this->complexTypes[$p][$type ->name]['order'] == 'sequence' &&902 array_key_exists('elements', $this->complexTypes[$p][$type ->name])) {903 reset($this->complexTypes[$p][$type ->name]['elements']);887 $p = $this->ns[$type_namespace]; 888 if ($p && !empty($this->complexTypes[$p][$type])) { 889 if ($arrayType = $this->complexTypes[$p][$type]['arrayType']) { 890 $type = 'Array'; 891 } elseif ($this->complexTypes[$p][$type]['order'] == 'sequence' && 892 array_key_exists('elements', $this->complexTypes[$p][$type])) { 893 reset($this->complexTypes[$p][$type]['elements']); 904 894 // assume an array 905 if (count($this->complexTypes[$p][$type ->name]['elements']) == 1) {906 $arg = current($this->complexTypes[$p][$type ->name]['elements']);895 if (count($this->complexTypes[$p][$type]['elements']) == 1) { 896 $arg = current($this->complexTypes[$p][$type]['elements']); 907 897 $arrayType = $arg['type']; 908 $type ->name= 'Array';898 $type = 'Array'; 909 899 } else { 910 foreach ($this->complexTypes[$p][$type ->name]['elements'] as $element) {911 if ($element['name'] == $type ->name) {900 foreach ($this->complexTypes[$p][$type]['elements'] as $element) { 901 if ($element['name'] == $type) { 912 902 $arrayType = $element['type']; 913 $type ->name= $element['type'];903 $type = $element['type']; 914 904 } 915 905 } 916 906 } 917 907 } else { 918 $type ->name= 'Struct';919 } 920 return array($type ->name, $arrayType, $type->namespace, null);908 $type = 'Struct'; 909 } 910 return array($type, $arrayType, $type_namespace, null); 921 911 } 922 912 } … … 1038 1028 // Try to retrieve WSDL from cache 1039 1029 $cachename = $this->_cacheDir() . '/' . md5($wsdl_fname). ' .wsdl'; 1040 if (file_exists($cachename) && 1041 $file_data = file_get_contents($cachename)) { 1042 $md5_wsdl = md5($file_data); 1030 if (file_exists($cachename)) { 1031 $wf = fopen($cachename, 'rb'); 1032 if ($wf) { 1033 // Reading cached file 1034 $file_data = fread($wf, filesize($cachename)); 1035 $md5_wsdl = md5($file_data); 1036 fclose($wf); 1037 } 1043 1038 if ($cache) { 1044 1039 if ($cache != $md5_wsdl) { … … 1048 1043 $fi = stat($cachename); 1049 1044 $cache_mtime = $fi[8]; 1045 //print cache_mtime, time() 1050 1046 if ($cache_mtime + $this->_cacheMaxAge < time()) { 1051 // Expired, refetch. 1052 $md5_wsdl = ''; 1053 } 1054 } 1055 } 1056 } 1057 1058 // Not cached or not using cache. Retrieve WSDL from URL 1047 // expired 1048 $md5_wsdl = ''; // refetch 1049 } 1050 } 1051 } 1052 } 1053 1059 1054 if (!$md5_wsdl) { 1060 // Is it a local file? 1061 if (strpos($wsdl_fname, 'file://') === 0) { 1062 $wsdl_fname = substr($wsdl_fname, 7); 1055 // Not cached or not using cache. Retrieve WSDL from URL 1056 1057 // is it a local file? 1058 // this section should be replace by curl at some point 1059 if (!preg_match('/^(https?|file):\/\//', $wsdl_fname)) { 1063 1060 if (!file_exists($wsdl_fname)) { 1064 return $this->_raiseSoapFault( 'Unable to read local WSDL file', $wsdl_fname);1061 return $this->_raiseSoapFault("Unable to read local WSDL $wsdl_fname", $wsdl_fname); 1065 1062 } 1066 1063 $file_data = file_get_contents($wsdl_fname); 1067 } elseif (!preg_match('|^https?://|', $wsdl_fname)) {1068 return $this->_raiseSoapFault('Unknown schema of WSDL URL', $wsdl_fname);1069 1064 } else { 1070 1065 $uri = explode('?', $wsdl_fname); 1071 $rq = new HTTP_Request($uri[0], $proxy_params);1066 $rq =& new HTTP_Request($uri[0], $proxy_params); 1072 1067 // the user agent HTTP_Request uses fouls things up 1073 1068 if (isset($uri[1])) { … … 1079 1074 isset($proxy_params['proxy_user']) && 1080 1075 isset($proxy_params['proxy_pass'])) { 1081 $rq->setProxy($proxy_params['proxy_host'], 1082 $proxy_params['proxy_port'], 1083 $proxy_params['proxy_user'], 1084 $proxy_params['proxy_pass']); 1076 $rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port'], 1077 $proxy_params['proxy_user'], $proxy_params['proxy_pass']); 1085 1078 } elseif (isset($proxy_params['proxy_host']) && 1086 1079 isset($proxy_params['proxy_port'])) { 1087 $rq->setProxy($proxy_params['proxy_host'], 1088 $proxy_params['proxy_port']); 1080 $rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port']); 1089 1081 } 1090 1082 … … 1107 1099 } 1108 1100 } 1109 1110 1101 if ($this->_cacheUse && $cache && $cache != $md5_wsdl) { 1111 return $this->_raiseSoapFault('WSDL Checksum error!', $wsdl_fname); 1112 } 1113 1102 return $this->_raiseSoapFault("WSDL Checksum error!", $wsdl_fname); 1103 } 1114 1104 return $file_data; 1115 1105 } … … 1985 1975 * <service>. 1986 1976 */ 1987 function SOAP_WSDL_ObjectParser( $objects, &$wsdl, $targetNamespace,1977 function SOAP_WSDL_ObjectParser(&$objects, &$wsdl, $targetNamespace, 1988 1978 $service_name, $service_desc = '') 1989 1979 { … … 1996 1986 1997 1987 // Parse each web service object 1998 $wsdl_ref = is_array($objects) ? $objects : array($objects);1988 $wsdl_ref = (is_array($objects)? $objects : array(&$objects)); 1999 1989 2000 1990 foreach ($wsdl_ref as $ref_item) { … … 2031 2021 $this->wsdl->namespaces[$this->tnsPrefix] = 'urn:' . $service_name; // Target namespace 2032 2022 $this->wsdl->namespaces['xsd'] = array_search('xsd', $this->_namespaces); // XML Schema 2033 $this->wsdl->namespaces[ SOAP_BASE::SOAPENCPrefix()] = array_search(SOAP_BASE::SOAPENCPrefix(), $this->_namespaces); // SOAP types2023 $this->wsdl->namespaces['SOAP-ENC'] = array_search('SOAP-ENC', $this->_namespaces); // SOAP types 2034 2024 2035 2025 // XXX Refactor $namespace/$ns for Shane :-) … … 2050 2040 * @param string $service_name Name of the WSDL <service>. 2051 2041 */ 2052 function _parse( $object, $schemaNamespace, $service_name)2042 function _parse(&$object, $schemaNamespace, $service_name) 2053 2043 { 2054 2044 // Create namespace prefix for the schema … … 2109 2099 // *** <wsdl:message> *** 2110 2100 foreach ($object->__dispatch_map as $operationName => $messages) { 2111 // We need at least 'in' and 'out' parameters.2112 if (!isset($messages['in']) || !isset($messages['out'])) {2113 return $this->_raiseSoapFault('The dispatch map for the method "' . $operationName . '" is missing an "in" or "out" definition.', 'urn:' . get_class($object));2114 }2115 2101 foreach ($messages as $messageType => $messageParts) { 2116 2102 unset($thisMessage);
Note: See TracChangeset
for help on using the changeset viewer.
