Ignore:
Timestamp:
2011/10/31 13:54:41 (15 years ago)
Author:
kotani
Message:

#1521 (PEAR::SOAP 配布と異なる部分がある)

  • 新しいバージョンの配布ファイルを上書きすることで解決
  • →2.11.4には含めないため一旦コミットキャンセル

#1522 (PEAR::SOAP をバージョンアップ)

  • 0.11.0 -> 0.12.0
  • →2.11.4には含めないため一旦コミットキャンセル
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_11-dev/data/module/SOAP/WSDL.php

    r21299 r21304  
    2525require_once 'SOAP/Base.php'; 
    2626require_once 'SOAP/Fault.php'; 
    27 require_once 'HTTP/Request.php'; 
     27require_once 'Request.php'; 
    2828 
    2929define('WSDL_CACHE_MAX_AGE', 43200); 
     
    3737 * 
    3838 * @todo 
     39 * - add wsdl caching 
    3940 * - refactor namespace handling ($namespace/$ns) 
    4041 * - implement IDL type syntax declaration so we can generate WSDL 
     
    230231     *                                 service. 
    231232     */ 
    232     function parseObject($wsdl_obj, $targetNamespace, $service_name, 
     233    function parseObject(&$wsdl_obj, $targetNamespace, $service_name, 
    233234                         $service_desc = '') 
    234235    { 
    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         } 
    242243    } 
    243244 
     
    313314            $opData = $this->bindings[$binding]['operations'][$operation]; 
    314315        } 
    315         // Get operation data from porttype. 
     316        // get operation data from porttype 
    316317        $portType = $this->bindings[$binding]['type']; 
    317318        if (!$portType) { 
     
    405406        } 
    406407 
    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                        } 
    434431                    } 
    435432                } 
     
    854851    } 
    855852 
    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) 
    864854    { 
    865855        // see if it's a complex type so we can deal properly with 
     
    869859            // look up the name in the wsdl and validate the type. 
    870860            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'])) { 
    879869                        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']); 
    881871                        return array('Array', $arraytype, $arraytype_ns, $array_depth); 
    882872                    } 
    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) { 
    892882            $arrayType = null; 
    893883            // XXX TODO: 
     
    895885            // types in wsdl need to do a generalized function to figure out 
    896886            // 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']); 
    904894                    // 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']); 
    907897                        $arrayType = $arg['type']; 
    908                         $type->name = 'Array'; 
     898                        $type = 'Array'; 
    909899                    } 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) { 
    912902                                $arrayType = $element['type']; 
    913                                 $type->name = $element['type']; 
     903                                $type = $element['type']; 
    914904                            } 
    915905                        } 
    916906                    } 
    917907                } 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); 
    921911            } 
    922912        } 
     
    10381028            // Try to retrieve WSDL from cache 
    10391029            $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                } 
    10431038                if ($cache) { 
    10441039                    if ($cache != $md5_wsdl) { 
     
    10481043                    $fi = stat($cachename); 
    10491044                    $cache_mtime = $fi[8]; 
     1045                    //print cache_mtime, time() 
    10501046                    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 
    10591054        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)) { 
    10631060                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); 
    10651062                } 
    10661063                $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); 
    10691064            } else { 
    10701065                $uri = explode('?', $wsdl_fname); 
    1071                 $rq = new HTTP_Request($uri[0], $proxy_params); 
     1066                $rq =& new HTTP_Request($uri[0], $proxy_params); 
    10721067                // the user agent HTTP_Request uses fouls things up 
    10731068                if (isset($uri[1])) { 
     
    10791074                    isset($proxy_params['proxy_user']) && 
    10801075                    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']); 
    10851078                } elseif (isset($proxy_params['proxy_host']) && 
    10861079                          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']); 
    10891081                } 
    10901082 
     
    11071099            } 
    11081100        } 
    1109  
    11101101        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        } 
    11141104        return $file_data; 
    11151105    } 
     
    19851975     *                                 <service>. 
    19861976     */ 
    1987     function SOAP_WSDL_ObjectParser($objects, &$wsdl, $targetNamespace, 
     1977    function SOAP_WSDL_ObjectParser(&$objects, &$wsdl, $targetNamespace, 
    19881978                                    $service_name, $service_desc = '') 
    19891979    { 
     
    19961986 
    19971987        // Parse each web service object 
    1998         $wsdl_ref = is_array($objects) ? $objects : array($objects); 
     1988        $wsdl_ref = (is_array($objects)? $objects : array(&$objects)); 
    19991989 
    20001990        foreach ($wsdl_ref as $ref_item) { 
     
    20312021        $this->wsdl->namespaces[$this->tnsPrefix] = 'urn:' . $service_name;                 // Target namespace 
    20322022        $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 types 
     2023        $this->wsdl->namespaces['SOAP-ENC'] = array_search('SOAP-ENC', $this->_namespaces); // SOAP types 
    20342024 
    20352025        // XXX Refactor $namespace/$ns for Shane :-) 
     
    20502040     * @param string $service_name     Name of the WSDL <service>. 
    20512041     */ 
    2052     function _parse($object, $schemaNamespace, $service_name) 
     2042    function _parse(&$object, $schemaNamespace, $service_name) 
    20532043    { 
    20542044        // Create namespace prefix for the schema 
     
    21092099        // *** <wsdl:message> *** 
    21102100        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             } 
    21152101            foreach ($messages as $messageType => $messageParts) { 
    21162102                unset($thisMessage); 
Note: See TracChangeset for help on using the changeset viewer.