Ignore:
Timestamp:
2011/10/25 00:02:55 (12 years ago)
Author:
Seasoft
Message:

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

  • 新しいバージョンの配布ファイルを上書きすることで解決

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

  • 0.11.0 -> 0.12.0
File:
1 edited

Legend:

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

    r20119 r21299  
    2525require_once 'SOAP/Base.php'; 
    2626require_once 'SOAP/Fault.php'; 
    27 require_once 'Request.php'; 
     27require_once 'HTTP/Request.php'; 
    2828 
    2929define('WSDL_CACHE_MAX_AGE', 43200); 
     
    3737 * 
    3838 * @todo 
    39  * - add wsdl caching 
    4039 * - refactor namespace handling ($namespace/$ns) 
    4140 * - implement IDL type syntax declaration so we can generate WSDL 
     
    231230     *                                 service. 
    232231     */ 
    233     function parseObject(&$wsdl_obj, $targetNamespace, $service_name, 
     232    function parseObject($wsdl_obj, $targetNamespace, $service_name, 
    234233                         $service_desc = '') 
    235234    { 
    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          } 
     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        } 
    243242    } 
    244243 
     
    314313            $opData = $this->bindings[$binding]['operations'][$operation]; 
    315314        } 
    316         // get operation data from porttype 
     315        // Get operation data from porttype. 
    317316        $portType = $this->bindings[$binding]['type']; 
    318317        if (!$portType) { 
     
    406405        } 
    407406 
    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; 
    431434                    } 
    432435                } 
     
    851854    } 
    852855 
    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) 
    854864    { 
    855865        // see if it's a complex type so we can deal properly with 
     
    859869            // look up the name in the wsdl and validate the type. 
    860870            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'])) { 
    869879                        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']); 
    871881                        return array('Array', $arraytype, $arraytype_ns, $array_depth); 
    872882                    } 
    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) { 
    882892            $arrayType = null; 
    883893            // XXX TODO: 
     
    885895            // types in wsdl need to do a generalized function to figure out 
    886896            // 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']); 
    894904                    // 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']); 
    897907                        $arrayType = $arg['type']; 
    898                         $type = 'Array'; 
     908                        $type->name = 'Array'; 
    899909                    } 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) { 
    902912                                $arrayType = $element['type']; 
    903                                 $type = $element['type']; 
     913                                $type->name = $element['type']; 
    904914                            } 
    905915                        } 
    906916                    } 
    907917                } 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); 
    911921            } 
    912922        } 
     
    10281038            // Try to retrieve WSDL from cache 
    10291039            $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); 
    10381043                if ($cache) { 
    10391044                    if ($cache != $md5_wsdl) { 
     
    10431048                    $fi = stat($cachename); 
    10441049                    $cache_mtime = $fi[8]; 
    1045                     //print cache_mtime, time() 
    10461050                    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 
    10541059        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); 
    10601063                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); 
    10621065                } 
    10631066                $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); 
    10641069            } else { 
    10651070                $uri = explode('?', $wsdl_fname); 
    1066                 $rq =& new HTTP_Request($uri[0], $proxy_params); 
     1071                $rq = new HTTP_Request($uri[0], $proxy_params); 
    10671072                // the user agent HTTP_Request uses fouls things up 
    10681073                if (isset($uri[1])) { 
     
    10741079                    isset($proxy_params['proxy_user']) && 
    10751080                    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']); 
    10781085                } elseif (isset($proxy_params['proxy_host']) && 
    10791086                          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']); 
    10811089                } 
    10821090 
     
    10991107            } 
    11001108        } 
     1109 
    11011110        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 
    11041114        return $file_data; 
    11051115    } 
     
    19751985     *                                 <service>. 
    19761986     */ 
    1977     function SOAP_WSDL_ObjectParser(&$objects, &$wsdl, $targetNamespace, 
     1987    function SOAP_WSDL_ObjectParser($objects, &$wsdl, $targetNamespace, 
    19781988                                    $service_name, $service_desc = '') 
    19791989    { 
     
    19861996 
    19871997        // Parse each web service object 
    1988         $wsdl_ref = (is_array($objects)? $objects : array(&$objects)); 
     1998        $wsdl_ref = is_array($objects) ? $objects : array($objects); 
    19891999 
    19902000        foreach ($wsdl_ref as $ref_item) { 
     
    20212031        $this->wsdl->namespaces[$this->tnsPrefix] = 'urn:' . $service_name;                 // Target namespace 
    20222032        $this->wsdl->namespaces['xsd'] = array_search('xsd', $this->_namespaces);           // XML Schema 
    2023         $this->wsdl->namespaces['SOAP-ENC'] = array_search('SOAP-ENC', $this->_namespaces); // SOAP types 
     2033        $this->wsdl->namespaces[SOAP_BASE::SOAPENCPrefix()] = array_search(SOAP_BASE::SOAPENCPrefix(), $this->_namespaces); // SOAP types 
    20242034 
    20252035        // XXX Refactor $namespace/$ns for Shane :-) 
     
    20402050     * @param string $service_name     Name of the WSDL <service>. 
    20412051     */ 
    2042     function _parse(&$object, $schemaNamespace, $service_name) 
     2052    function _parse($object, $schemaNamespace, $service_name) 
    20432053    { 
    20442054        // Create namespace prefix for the schema 
     
    20992109        // *** <wsdl:message> *** 
    21002110        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            } 
    21012115            foreach ($messages as $messageType => $messageParts) { 
    21022116                unset($thisMessage); 
Note: See TracChangeset for help on using the changeset viewer.