⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wsdl.php

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 PHP
📖 第 1 页 / 共 5 页
字号:
                if (!file_exists($wsdl_fname)) {
                    return $this->_raiseSoapFault("Unable to read local WSDL $wsdl_fname", $wsdl_fname);
                }
                if (function_exists('file_get_contents')) {
                    $file_data = file_get_contents($wsdl_fname);
                } else {
                    $file_data = implode('',file($wsdl_fname));
                }
            } else {
                $uri = explode('?', $wsdl_fname);
                $rq =& new HTTP_Request($uri[0], $proxy_params);
                // the user agent HTTP_Request uses fouls things up
                if (isset($uri[1])) {
                    $rq->addRawQueryString($uri[1]);
                }

                if (isset($proxy_params['proxy_host']) &&
                    isset($proxy_params['proxy_port']) &&
                    isset($proxy_params['proxy_user']) &&
                    isset($proxy_params['proxy_pass'])) {
                    $rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port'],
                                  $proxy_params['proxy_user'], $proxy_params['proxy_pass']);
                } elseif (isset($proxy_params['proxy_host']) &&
                          isset($proxy_params['proxy_port'])) {
                    $rq->setProxy($proxy_params['proxy_host'], $proxy_params['proxy_port']);
                }

                $result = $rq->sendRequest();
                if (PEAR::isError($result)) {
                    return $this->_raiseSoapFault("Unable to retrieve WSDL $wsdl_fname," . $rq->getResponseCode(), $wsdl_fname);
                }
                $file_data = $rq->getResponseBody();
                if (!$file_data) {
                    return $this->_raiseSoapFault("Unable to retrieve WSDL $wsdl_fname, no http body", $wsdl_fname);
                }
            }

            $md5_wsdl = md5($file_data);

            if ($this->_cacheUse) {
                $fp = fopen($cachename, "wb");
                fwrite($fp, $file_data);
                fclose($fp);
            }
        }
        if ($this->_cacheUse && $cache && $cache != $md5_wsdl) {
            return $this->_raiseSoapFault("WSDL Checksum error!", $wsdl_fname);
        }
        return $file_data;
    }

}

class SOAP_WSDL_Parser extends SOAP_Base
{

    /**
     * Define internal arrays of bindings, ports, operations,
     * messages, etc.
     */
    var $currentMessage;
    var $currentOperation;
    var $currentPortType;
    var $currentBinding;
    var $currentPort;

    /**
     * Parser vars.
     */
    var $cache;

    var $tns = null;
    var $soapns = array('soap');
    var $uri = '';
    var $wsdl = null;

    var $status = '';
    var $element_stack = array();
    var $parentElement = '';

    var $schema = '';
    var $schemaStatus = '';
    var $schema_stack = array();
    var $currentComplexType;
    var $schema_element_stack = array();
    var $currentElement;

    /**
     * constructor
     */
    function SOAP_WSDL_Parser($uri, &$wsdl, $docs = false)
    {
        parent::SOAP_Base('WSDLPARSER');
        $this->cache =& new SOAP_WSDL_Cache($wsdl->cacheUse, $wsdl->cacheMaxAge);
        $this->uri = $uri;
        $this->wsdl = &$wsdl;
        $this->docs = $docs;
        $this->parse($uri);
    }

    function parse($uri)
    {
        // Check whether content has been read.
        $fd = $this->cache->get($uri, $this->wsdl->proxy);
        if (PEAR::isError($fd)) {
            return $this->_raiseSoapFault($fd);
        }

        // Create an XML parser.
        $parser = xml_parser_create();
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
        xml_set_object($parser, $this);
        xml_set_element_handler($parser, 'startElement', 'endElement');
        if ($this->docs) {
            xml_set_character_data_handler($parser, 'characterData');
        }

        if (!xml_parse($parser, $fd, true)) {
            $detail = sprintf('XML error on line %d: %s',
                              xml_get_current_line_number($parser),
                              xml_error_string(xml_get_error_code($parser)));
            return $this->_raiseSoapFault("Unable to parse WSDL file $uri\n$detail");
        }
        xml_parser_free($parser);
        return true;
    }

    /**
     * start-element handler
     */
    function startElement($parser, $name, $attrs)
    {
        // Get element prefix.
        $qname =& new QName($name);
        if ($qname->ns) {
            $ns = $qname->ns;
            if ($ns && ((!$this->tns && strcasecmp($qname->name, 'definitions') == 0) || $ns == $this->tns)) {
                $name = $qname->name;
            }
        }
        $this->currentTag = $qname->name;
        $this->parentElement = '';
        $stack_size = count($this->element_stack);
        if ($stack_size) {
            $this->parentElement = $this->element_stack[$stack_size - 1];
        }
        $this->element_stack[] = $this->currentTag;

        // Find status, register data.
        switch ($this->status) {
        case 'types':
            // sect 2.2 wsdl:types
            // children: xsd:schema
            $parent_tag = '';
            $stack_size = count($this->schema_stack);
            if ($stack_size) {
                $parent_tag = $this->schema_stack[$stack_size - 1];
            }

            switch ($qname->name) {
            case 'schema':
                // No parent should be in the stack.
                if (!$parent_tag || $parent_tag == 'types') {
                    if (array_key_exists('targetNamespace', $attrs)) {
                        $this->schema = $this->wsdl->getNamespaceAttributeName($attrs['targetNamespace']);
                    } else {
                        $this->schema = $this->wsdl->getNamespaceAttributeName($this->wsdl->tns);
                    }
                    $this->wsdl->complexTypes[$this->schema] = array();
                    $this->wsdl->elements[$this->schema] = array();
                }
                break;

            case 'complexType':
                if ($parent_tag == 'schema') {
                    $this->currentComplexType = $attrs['name'];
                    if (!isset($attrs['namespace'])) {
                        $attrs['namespace'] = $this->schema;
                    }
                    $this->wsdl->complexTypes[$this->schema][$this->currentComplexType] = $attrs;
                    if (array_key_exists('base', $attrs)) {
                        $qn =& new QName($attrs['base']);
                        $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['type'] = $qn->name;
                        $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['namespace'] = $qn->ns;
                    } else {
                        $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['type'] = 'Struct';
                    }
                    $this->schemaStatus = 'complexType';
                } else {
                    $this->wsdl->elements[$this->schema][$this->currentElement]['complex'] = true;
                }
                break;

            case 'element':
                if (isset($attrs['type'])) {
                    $qn =& new QName($attrs['type']);
                    $attrs['type'] = $qn->name;
                    if ($qn->ns && array_key_exists($qn->ns, $this->wsdl->namespaces)) {
                        $attrs['namespace'] = $qn->ns;
                    }
                }

                $parentElement = '';
                $stack_size = count($this->schema_element_stack);
                if ($stack_size > 0) {
                    $parentElement = $this->schema_element_stack[$stack_size - 1];
                }

                if (isset($attrs['ref'])) {
                    $qn =& new QName($attrs['ref']);
                    $this->currentElement = $qn->name;
                } else {
                    $this->currentElement = $attrs['name'];
                }
                $this->schema_element_stack[] = $this->currentElement;
                if (!isset($attrs['namespace'])) {
                    $attrs['namespace'] = $this->schema;
                }

                if ($parent_tag == 'schema') {
                    $this->wsdl->elements[$this->schema][$this->currentElement] = $attrs;
                    $this->wsdl->elements[$this->schema][$this->currentElement]['complex'] = false;
                    $this->schemaStatus = 'element';
                } elseif ($this->currentComplexType) {
                    // we're inside a complexType
                    if ((isset($this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['order']) &&
                         $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['order'] == 'sequence')
                        && $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['type'] == 'Array') {
                        $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['arrayType'] = isset($attrs['type']) ? $attrs['type'] : null;
                    }
                    $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['elements'][$this->currentElement] = $attrs;
                } else {
                    $this->wsdl->elements[$this->schema][$parentElement]['elements'][$this->currentElement] = $attrs;
                }
                break;

            case 'complexContent':
            case 'simpleContent':
                break;

            case 'extension':
            case 'restriction':
                if ($this->schemaStatus == 'complexType') {
                    if (!empty($attrs['base'])) {
                        $qn =& new QName($attrs['base']);
                        $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['type'] = $qn->name;

                        // Types that extend from other types aren't
                        // *of* those types. Reflect this by denoting
                        // which type they extend. I'm leaving the
                        // 'type' setting here since I'm not sure what
                        // removing it might break at the moment.
                        if ($qname->name == 'extension') {
                            $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['extends'] = $qn->name;
                        }
                    } else {
                        $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['type'] = 'Struct';
                    }
                }
                break;

            case 'sequence':
                if ($this->schemaStatus == 'complexType') {
                    $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['order'] = $qname->name;
                    if (!isset($this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['type'])) {
                        $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['type'] = 'Array';
                    }
                }
                break;

            case 'all':
                $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['order'] = $qname->name;
                if (!isset($this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['type'])) {
                    $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['type'] = 'Struct';
                }
                break;

            case 'choice':
                $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['order'] = $qname->name;
                if (!isset($this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['type'])) {
                    $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['type'] = 'Array';
                }

            case 'attribute':
                if ($this->schemaStatus == 'complexType') {
                    if (isset($attrs['name'])) {
                        $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['attribute'][$attrs['name']] = $attrs;
                    } else {
                        if (isset($attrs['ref'])) {
                            $q =& new QName($attrs['ref']);
                            foreach ($attrs as $k => $v) {
                                if ($k != 'ref' && strstr($k, $q->name)) {
                                    $vq =& new QName($v);
                                    if ($q->name == 'arrayType') {
                                        $this->wsdl->complexTypes[$this->schema][$this->currentComplexType][$q->name] = $vq->name. $vq->arrayInfo;
                                        $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['type'] = 'Array';
                                        $this->wsdl->complexTypes[$this->schema][$this->currentComplexType]['namespace'] = $vq->ns;
                                    } else {
                                        $this->wsdl->complexTypes[$this->schema][$this->currentComplexType][$q->name] = $vq->name;
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            }

            $this->schema_stack[] = $qname->name;
            break;

        case 'message':
            // sect 2.3 wsdl:message child wsdl:part
            switch ($qname->name) {
            case 'part':
                $qn = null;
                if (isset($attrs['type'])) {
                    $qn =& new QName($attrs['type']);
                } elseif (isset($attrs['element'])) {
                    $qn =& new QName($attrs['element']);
                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -