Changeset 21299 for branches/version-2_11-dev/data/module/SOAP/WSDL.php
- Timestamp:
- 2011/10/25 00:02:55 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_11-dev/data/module/SOAP/WSDL.php
r20119 r21299 25 25 require_once 'SOAP/Base.php'; 26 26 require_once 'SOAP/Fault.php'; 27 require_once ' Request.php';27 require_once 'HTTP/Request.php'; 28 28 29 29 define('WSDL_CACHE_MAX_AGE', 43200); … … 37 37 * 38 38 * @todo 39 * - add wsdl caching40 39 * - refactor namespace handling ($namespace/$ns) 41 40 * - implement IDL type syntax declaration so we can generate WSDL … … 231 230 * service. 232 231 */ 233 function parseObject( &$wsdl_obj, $targetNamespace, $service_name,232 function parseObject($wsdl_obj, $targetNamespace, $service_name, 234 233 $service_desc = '') 235 234 { 236 $parser = &new SOAP_WSDL_ObjectParser($wsdl_obj, $this,237 238 239 240 241 242 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 } 243 242 } 244 243 … … 314 313 $opData = $this->bindings[$binding]['operations'][$operation]; 315 314 } 316 // get operation data from porttype315 // Get operation data from porttype. 317 316 $portType = $this->bindings[$binding]['type']; 318 317 if (!$portType) { … … 406 405 } 407 406 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 } 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; 431 434 } 432 435 } … … 851 854 } 852 855 853 function getSchemaType($type, $name, $type_namespace) 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) 854 864 { 855 865 // see if it's a complex type so we can deal properly with … … 859 869 // look up the name in the wsdl and validate the type. 860 870 foreach ($this->complexTypes as $types) { 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'])) {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'])) { 869 879 list($arraytype_ns, $arraytype, $array_depth) = 870 $this->_getDeepestArrayType($types[$type ]['namespace'], $types[$type]['arrayType']);880 $this->_getDeepestArrayType($types[$type->name]['namespace'], $types[$type->name]['arrayType']); 871 881 return array('Array', $arraytype, $arraytype_ns, $array_depth); 872 882 } 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) {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) { 882 892 $arrayType = null; 883 893 // XXX TODO: … … 885 895 // types in wsdl need to do a generalized function to figure out 886 896 // complex types 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']);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']); 894 904 // assume an array 895 if (count($this->complexTypes[$p][$type ]['elements']) == 1) {896 $arg = current($this->complexTypes[$p][$type ]['elements']);905 if (count($this->complexTypes[$p][$type->name]['elements']) == 1) { 906 $arg = current($this->complexTypes[$p][$type->name]['elements']); 897 907 $arrayType = $arg['type']; 898 $type = 'Array';908 $type->name = 'Array'; 899 909 } else { 900 foreach ($this->complexTypes[$p][$type ]['elements'] as $element) {901 if ($element['name'] == $type ) {910 foreach ($this->complexTypes[$p][$type->name]['elements'] as $element) { 911 if ($element['name'] == $type->name) { 902 912 $arrayType = $element['type']; 903 $type = $element['type'];913 $type->name = $element['type']; 904 914 } 905 915 } 906 916 } 907 917 } else { 908 $type = 'Struct';909 } 910 return array($type , $arrayType, $type_namespace, null);918 $type->name = 'Struct'; 919 } 920 return array($type->name, $arrayType, $type->namespace, null); 911 921 } 912 922 } … … 1028 1038 // Try to retrieve WSDL from cache 1029 1039 $cachename = $this->_cacheDir() . '/' . md5($wsdl_fname). ' .wsdl'; 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 } 1040 if (file_exists($cachename) && 1041 $file_data = file_get_contents($cachename)) { 1042 $md5_wsdl = md5($file_data); 1038 1043 if ($cache) { 1039 1044 if ($cache != $md5_wsdl) { … … 1043 1048 $fi = stat($cachename); 1044 1049 $cache_mtime = $fi[8]; 1045 //print cache_mtime, time()1046 1050 if ($cache_mtime + $this->_cacheMaxAge < time()) { 1047 // expired 1048 $md5_wsdl = ''; // refetch 1049 } 1050 } 1051 } 1052 } 1053 1051 // Expired, refetch. 1052 $md5_wsdl = ''; 1053 } 1054 } 1055 } 1056 } 1057 1058 // Not cached or not using cache. Retrieve WSDL from URL 1054 1059 if (!$md5_wsdl) { 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)) { 1060 // Is it a local file? 1061 if (strpos($wsdl_fname, 'file://') === 0) { 1062 $wsdl_fname = substr($wsdl_fname, 7); 1060 1063 if (!file_exists($wsdl_fname)) { 1061 return $this->_raiseSoapFault( "Unable to read local WSDL $wsdl_fname", $wsdl_fname);1064 return $this->_raiseSoapFault('Unable to read local WSDL file', $wsdl_fname); 1062 1065 } 1063 1066 $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); 1064 1069 } else { 1065 1070 $uri = explode('?', $wsdl_fname); 1066 $rq = &new HTTP_Request($uri[0], $proxy_params);1071 $rq = new HTTP_Request($uri[0], $proxy_params); 1067 1072 // the user agent HTTP_Request uses fouls things up 1068 1073 if (isset($uri[1])) { … … 1074 1079 isset($proxy_params['proxy_user']) && 1075 1080 isset($proxy_params['proxy_pass'])) { 1076 $rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port'], 1077 $proxy_params['proxy_user'], $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']); 1078 1085 } elseif (isset($proxy_params['proxy_host']) && 1079 1086 isset($proxy_params['proxy_port'])) { 1080 $rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port']); 1087 $rq->setProxy($proxy_params['proxy_host'], 1088 $proxy_params['proxy_port']); 1081 1089 } 1082 1090 … … 1099 1107 } 1100 1108 } 1109 1101 1110 if ($this->_cacheUse && $cache && $cache != $md5_wsdl) { 1102 return $this->_raiseSoapFault("WSDL Checksum error!", $wsdl_fname); 1103 } 1111 return $this->_raiseSoapFault('WSDL Checksum error!', $wsdl_fname); 1112 } 1113 1104 1114 return $file_data; 1105 1115 } … … 1975 1985 * <service>. 1976 1986 */ 1977 function SOAP_WSDL_ObjectParser( &$objects, &$wsdl, $targetNamespace,1987 function SOAP_WSDL_ObjectParser($objects, &$wsdl, $targetNamespace, 1978 1988 $service_name, $service_desc = '') 1979 1989 { … … 1986 1996 1987 1997 // Parse each web service object 1988 $wsdl_ref = (is_array($objects)? $objects : array(&$objects));1998 $wsdl_ref = is_array($objects) ? $objects : array($objects); 1989 1999 1990 2000 foreach ($wsdl_ref as $ref_item) { … … 2021 2031 $this->wsdl->namespaces[$this->tnsPrefix] = 'urn:' . $service_name; // Target namespace 2022 2032 $this->wsdl->namespaces['xsd'] = array_search('xsd', $this->_namespaces); // XML Schema 2023 $this->wsdl->namespaces[ 'SOAP-ENC'] = array_search('SOAP-ENC', $this->_namespaces); // SOAP types2033 $this->wsdl->namespaces[SOAP_BASE::SOAPENCPrefix()] = array_search(SOAP_BASE::SOAPENCPrefix(), $this->_namespaces); // SOAP types 2024 2034 2025 2035 // XXX Refactor $namespace/$ns for Shane :-) … … 2040 2050 * @param string $service_name Name of the WSDL <service>. 2041 2051 */ 2042 function _parse( &$object, $schemaNamespace, $service_name)2052 function _parse($object, $schemaNamespace, $service_name) 2043 2053 { 2044 2054 // Create namespace prefix for the schema … … 2099 2109 // *** <wsdl:message> *** 2100 2110 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 } 2101 2115 foreach ($messages as $messageType => $messageParts) { 2102 2116 unset($thisMessage);
Note: See TracChangeset
for help on using the changeset viewer.