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

📄 parser.php

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
            $this->status = 'header';
            $this->header_struct_name[] = $this->curent_root_struct_name = $qname->name;
            $this->header_struct[] = $this->curent_root_struct = $pos;
            $this->message[$pos]['type'] = 'Struct';
        } elseif (strcasecmp('body', $qname->name) == 0) {
            $this->status = 'body';
            $this->bodyDepth = $this->depth;

        // Set method
        } elseif ($this->status == 'body') {
            // Is this element allowed to be a root?
            // XXX this needs to be optimized, we loop through attrs twice now.
            $can_root = $this->depth == $this->bodyDepth + 1;
            if ($can_root) {
                foreach ($attrs as $key => $value) {
                    if (stristr($key, ':root') && !$value) {
                        $can_root = FALSE;
                    }
                }
            }

            if ($can_root) {
                $this->status = 'method';
                $this->root_struct_name[] = $this->curent_root_struct_name = $qname->name;
                $this->root_struct[] = $this->curent_root_struct = $pos;
                $this->message[$pos]['type'] = 'Struct';
            }
        }

        // Set my status.
        $this->message[$pos]['status'] = $this->status;

        // Set name.
        $this->message[$pos]['name'] = htmlspecialchars($qname->name);

        // Set attributes.
        $this->message[$pos]['attrs'] = $attrs;

        // Loop through attributes, logging ns and type declarations.
        foreach ($attrs as $key => $value) {
            // If ns declarations, add to class level array of valid
            // namespaces.
            $kqn =& new QName($key);
            if ($kqn->ns == 'xmlns') {
                $prefix = $kqn->name;

                if (in_array($value, $this->_XMLSchema)) {
                    $this->_setSchemaVersion($value);
                }

                $this->_namespaces[$value] = $prefix;

            // Set method namespace.
            } elseif ($key == 'xmlns') {
                $qname->ns = $this->_getNamespacePrefix($value);
                $qname->namespace = $value;
            } elseif ($kqn->name == 'actor') {
                $this->message[$pos]['actor'] = $value;
            } elseif ($kqn->name == 'mustUnderstand') {
                $this->message[$pos]['mustUnderstand'] = $value;

            // If it's a type declaration, set type.
            } elseif ($kqn->name == 'type') {
                $vqn =& new QName($value);
                $this->message[$pos]['type'] = $vqn->name;
                $this->message[$pos]['type_namespace'] = $this->_getNamespaceForPrefix($vqn->ns);
                // Should do something here with the namespace of
                // specified type?

            } elseif ($kqn->name == 'arrayType') {
                $vqn =& new QName($value);
                $this->message[$pos]['type'] = 'Array';
                if (isset($vqn->arraySize)) {
                    $this->message[$pos]['arraySize'] = $vqn->arraySize;
                }
                $this->message[$pos]['arrayType'] = $vqn->name;

            } elseif ($kqn->name == 'offset') {
                $this->message[$pos]['arrayOffset'] = split(',', substr($value, 1, strlen($value) - 2));

            } elseif ($kqn->name == 'id') {
                // Save id to reference array.
                $this->references[$value] = $pos;
                $this->message[$pos]['id'] = $value;

            } elseif ($kqn->name == 'href') {
                if ($value[0] == '#') {
                    $ref = substr($value, 1);
                    if (isset($this->references[$ref])) {
                        // cdata, type, inval.
                        $ref_pos = $this->references[$ref];
                        $this->message[$pos]['children'] = &$this->message[$ref_pos]['children'];
                        $this->message[$pos]['cdata'] = &$this->message[$ref_pos]['cdata'];
                        $this->message[$pos]['type'] = &$this->message[$ref_pos]['type'];
                        $this->message[$pos]['arraySize'] = &$this->message[$ref_pos]['arraySize'];
                        $this->message[$pos]['arrayType'] = &$this->message[$ref_pos]['arrayType'];
                    } else {
                        // Reverse reference, store in 'need reference'.
                        if (!isset($this->need_references[$ref])) {
                            $this->need_references[$ref] = array();
                        }
                        $this->need_references[$ref][] = $pos;
                    }
                } elseif (isset($this->attachments[$value])) {
                    $this->message[$pos]['cdata'] = $this->attachments[$value];
                }
            }
        }
        // See if namespace is defined in tag.
        if (array_key_exists('xmlns:' . $qname->ns, $attrs)) {
            $namespace = $attrs['xmlns:' . $qname->ns];
        } elseif ($qname->ns && !$qname->namespace) {
            $namespace = $this->_getNamespaceForPrefix($qname->ns);
        } else {
            // Get namespace.
            $namespace = $qname->namespace ? $qname->namespace : $this->default_namespace;
        }
        $this->message[$pos]['namespace'] = $namespace;
        $this->default_namespace = $namespace;
    }

    /**
     * endElement
     * end-element handler used with xml parser
     *
     * @access private
     */
    function endElement($parser, $name)
    {
        // Position of current element is equal to the last value left
        // in depth_array for my depth.
        $pos = $this->depth_array[$this->depth];

        // Bring depth down a notch.
        $this->depth--;
        $qname =& new QName($name);

        // Get type if not explicitly declared in an xsi:type attribute.
        // XXX check on integrating wsdl validation here
        if ($this->message[$pos]['type'] == '') {
            if (isset($this->message[$pos]['children'])) {
                /* this is slow, need to look at some faster method
                $children = explode('|', $this->message[$pos]['children']);
                if (count($children) > 2 &&
                    $this->message[$children[1]]['name'] == $this->message[$children[2]]['name']) {
                    $this->message[$pos]['type'] = 'Array';
                } else {
                    $this->message[$pos]['type'] = 'Struct';
                }*/
                $this->message[$pos]['type'] = 'Struct';
            } else {
                $parent = $this->message[$pos]['parent'];
                if ($this->message[$parent]['type'] == 'Array' &&
                  array_key_exists('arrayType', $this->message[$parent])) {
                    $this->message[$pos]['type'] = $this->message[$parent]['arrayType'];
                } else {
                    $this->message[$pos]['type'] = 'string';
                }
            }
        }

        // If tag we are currently closing is the method wrapper.
        if ($pos == $this->curent_root_struct) {
            $this->status = 'body';
        } elseif ($qname->name == 'Body' || $qname->name == 'Header') {
            $this->status = 'envelope';
        }

        // Set parent back to my parent.
        $this->parent = $this->message[$pos]['parent'];

        // Handle any reverse references now.
        $idref = $this->message[$pos]['id'];

        if ($idref != '' && array_key_exists($idref, $this->need_references)) {
            foreach ($this->need_references[$idref] as $ref_pos) {
                // XXX is this stuff there already?
                $this->message[$ref_pos]['children'] = &$this->message[$pos]['children'];
                $this->message[$ref_pos]['cdata'] = &$this->message[$pos]['cdata'];
                $this->message[$ref_pos]['type'] = &$this->message[$pos]['type'];
                $this->message[$ref_pos]['arraySize'] = &$this->message[$pos]['arraySize'];
                $this->message[$ref_pos]['arrayType'] = &$this->message[$pos]['arrayType'];
            }
        }
    }

    /**
     * characterData
     * element content handler used with xml parser
     *
     * @access private
     */
    function characterData($parser, $data)
    {
        $pos = $this->depth_array[$this->depth];
        if (isset($this->message[$pos]['cdata'])) {
            $this->message[$pos]['cdata'] .= $data;
        } else {
            $this->message[$pos]['cdata'] = $data;
        }
    }

    /**
     * Returns an array of responses.
     *
     * After parsing a SOAP message, use this to get the response.
     *
     * @return array
     * @access public
     */
    function &getResponse()
    {
        if (isset($this->root_struct[0]) &&
            $this->root_struct[0]) {
            $response =& $this->buildResponse($this->root_struct[0]);
        } else {
            $response =& $this->_raiseSoapFault("couldn't build response");
        }
        return $response;
    }

    /**
     * Returns an array of header responses.
     *
     * After parsing a SOAP message, use this to get the response.
     *
     * @return array
     * @access public
     */
    function &getHeaders()
    {
        if (isset($this->header_struct[0]) &&
            $this->header_struct[0]) {
            $response = &$this->buildResponse($this->header_struct[0]);
        } else {
            // We don't fault if there are no headers; that can be handled by
            // the application if necessary.
            $response = null;
        }
        return $response;
    }

    /**
     * decodeEntities
     *
     * removes entities from text
     *
     * @param string
     * @return   string
     * @access private
     */
    function decodeEntities($text)
    {
        $trans_tbl = array_flip($this->entities);
        return strtr($text, $trans_tbl);
    }

}

⌨️ 快捷键说明

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