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

📄 client.php

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
    {
        if (!is_null($value)) {
            if (!isset($this->__options[$category])) {
                $this->__options[$category] = array();
            }
            $this->__options[$category][$option] = $value;
        } else {
            $this->__options[$category] = $option;
        }
    }

    /**
     * Call method supporting the overload extension.
     *
     * If the overload extension is loaded, you can call the client class with
     * a soap method name:
     * <code>
     * $soap = new SOAP_Client(....);
     * $value = $soap->getStockQuote('MSFT');
     * </code>
     *
     * @access public
     *
     * @param string $method        The method to call.
     * @param array $params         The method parameters.
     * @param string $return_value  Will get the method's return value
     *                              assigned.
     *
     * @return boolean  Always true.
     */
    function _call($method, $params, &$return_value)
    {
        // Overloading lowercases the method name, we need to look into the
        // wsdl and try to find the correct method name to get the correct
        // case for the call.
        if ($this->_wsdl) {
            $this->_wsdl->matchMethod($method);
        }

        $return_value =& $this->call($method, $params);

        return true;
    }

    function &__getlastrequest()
    {
        $request =& $this->__last_request;
        return $request;
    }

    function &__getlastresponse()
    {
        $response =& $this->__last_response;
        return $response;
    }

    function __use($use)
    {
        $this->__options['use'] = $use;
    }

    function __style($style)
    {
        $this->__options['style'] = $style;
    }

    function __trace($level)
    {
        $this->__options['trace'] = $level;
    }

    function &__generate($method, &$params, $namespace = false,
                         $soapAction = false)
    {
        $this->fault = null;
        $this->__options['input']='parse';
        $this->__options['result']='parse';
        $this->__options['parameters'] = false;

        if ($params && gettype($params) != 'array') {
            $params = array($params);
        }

        if (gettype($namespace) == 'array') {
            foreach ($namespace as $optname => $opt) {
                $this->__options[strtolower($optname)] = $opt;
            }
            if (isset($this->__options['namespace'])) {
                $namespace = $this->__options['namespace'];
            } else {
                $namespace = false;
            }
        } else {
            // We'll place $soapAction into our array for usage in the
            // transport.
            $this->__options['soapaction'] = $soapAction;
            $this->__options['namespace'] = $namespace;
        }

        if ($this->__endpointType == 'wsdl') {
            $this->_setSchemaVersion($this->_wsdl->xsd);

            // Get port name.
            if (!$this->_portName) {
                $this->_portName = $this->_wsdl->getPortName($method);
            }
            if (PEAR::isError($this->_portName)) {
                $fault =& $this->_raiseSoapFault($this->_portName);
                return $fault;
            }

            // Get endpoint.
            $this->_endpoint = $this->_wsdl->getEndpoint($this->_portName);
            if (PEAR::isError($this->_endpoint)) {
                $fault =& $this->_raiseSoapFault($this->_endpoint);
                return $fault;
            }

            // Get operation data.
            $opData = $this->_wsdl->getOperationData($this->_portName, $method);

            if (PEAR::isError($opData)) {
                $fault =& $this->_raiseSoapFault($opData);
                return $fault;
            }
            $namespace = $opData['namespace'];
            $this->__options['style'] = $opData['style'];
            $this->__options['use'] = $opData['input']['use'];
            $this->__options['soapaction'] = $opData['soapAction'];

            // Set input parameters.
            if ($this->__options['input'] == 'parse') {
                $this->__options['parameters'] = $opData['parameters'];
                $nparams = array();
                if (isset($opData['input']['parts']) &&
                    count($opData['input']['parts'])) {
                    $i = 0;
                    foreach ($opData['input']['parts'] as $name => $part) {
                        $xmlns = '';
                        $attrs = array();
                        // Is the name a complex type?
                        if (isset($part['element'])) {
                            $xmlns = $this->_wsdl->namespaces[$part['namespace']];
                            $part = $this->_wsdl->elements[$part['namespace']][$part['type']];
                            $name = $part['name'];
                        }
                        if (isset($params[$name]) ||
                            $this->_wsdl->getDataHandler($name, $part['namespace'])) {
                            $nparams[$name] =& $params[$name];
                        } else {
                            // We now force an associative array for
                            // parameters if using WSDL.
                            $fault =& $this->_raiseSoapFault("The named parameter $name is not in the call parameters.");
                            return $fault;
                        }
                        if (gettype($nparams[$name]) != 'object' ||
                            !is_a($nparams[$name], 'SOAP_Value')) {
                            // Type is likely a qname, split it apart, and get
                            // the type namespace from WSDL.
                            $qname =& new QName($part['type']);
                            if ($qname->ns) {
                                $type_namespace = $this->_wsdl->namespaces[$qname->ns];
                            } elseif (isset($part['namespace'])) {
                                $type_namespace = $this->_wsdl->namespaces[$part['namespace']];
                            } else {
                                $type_namespace = null;
                            }
                            $qname->namespace = $type_namespace;
                            $type = $qname->name;
                            $pqname = $name;
                            if ($xmlns) {
                                $pqname = '{' . $xmlns . '}' . $name;
                            }
                            $nparams[$name] =& new SOAP_Value($pqname,
                                                              $qname->fqn(),
                                                              $nparams[$name],
                                                              $attrs);
                        } else {
                            // WSDL fixups to the SOAP value.
                        }
                    }
                }
                $params =& $nparams;
                unset($nparams);
            }
        } else {
            $this->_setSchemaVersion(SOAP_XML_SCHEMA_VERSION);
        }

        // Serialize the message.
        $this->_section5 = (!isset($this->__options['use']) ||
                            $this->__options['use'] != 'literal');

        if (!isset($this->__options['style']) ||
            $this->__options['style'] == 'rpc') {
            $this->__options['style'] = 'rpc';
            $this->docparams = true;
            $mqname =& new QName($method, $namespace);
            $methodValue =& new SOAP_Value($mqname->fqn(), 'Struct', $params);
            $soap_msg = $this->_makeEnvelope($methodValue,
                                             $this->headersOut,
                                             $this->_encoding,
                                             $this->__options);
        } else {
            if (!$params) {
                $mqname =& new QName($method, $namespace);
                $mynull = null;
                $params =& new SOAP_Value($mqname->fqn(), 'Struct', $mynull);
            } elseif ($this->__options['input'] == 'parse') {
                if (is_array($params)) {
                    $nparams = array();
                    $keys = array_keys($params);
                    foreach ($keys as $k) {
                        if (gettype($params[$k]) != 'object') {
                            $nparams[] =& new SOAP_Value($k,
                                                         false,
                                                         $params[$k]);
                        } else {
                            $nparams[] =& $params[$k];
                        }
                    }
                    $params =& $nparams;
                }
                if ($this->__options['parameters']) {
                    $mqname =& new QName($method, $namespace);
                    $params =& new SOAP_Value($mqname->fqn(),
                                              'Struct',
                                              $params);
                }
            }
            $soap_msg = $this->_makeEnvelope($params,
                                             $this->headersOut,
                                             $this->_encoding,
                                             $this->__options);
        }
        unset($this->headersOut);

        if (PEAR::isError($soap_msg)) {
            $fault =& $this->_raiseSoapFault($soap_msg);
            return $fault;
        }

        // Handle MIME or DIME encoding.
        // TODO: DIME encoding should move to the transport, do it here for
        // now and for ease of getting it done.
        if (count($this->__attachments)) {
            if ((isset($this->__options['attachments']) &&
                 $this->__options['attachments'] == 'Mime') ||
                isset($this->__options['Mime'])) {
                $soap_msg =& $this->_makeMimeMessage($soap_msg,
                                                     $this->_encoding);
            } else {
                // default is dime
                $soap_msg =& $this->_makeDIMEMessage($soap_msg,
                                                     $this->_encoding);
                $this->__options['headers']['Content-Type'] = 'application/dime';
            }
            if (PEAR::isError($soap_msg)) {
                $fault =& $this->_raiseSoapFault($soap_msg);
                return $fault;
            }
        }

        // Instantiate client.
        if (is_array($soap_msg)) {
            $soap_data =& $soap_msg['body'];
            if (count($soap_msg['headers'])) {
                if (isset($this->__options['headers'])) {
                    $this->__options['headers'] = array_merge($this->__options['headers'], $soap_msg['headers']);
                } else {
                    $this->__options['headers'] = $soap_msg['headers'];
                }
            }
        } else {
            $soap_data =& $soap_msg;
        }

        return $soap_data;
    }

    function &__parse(&$response, $encoding, &$attachments)
    {
        // Parse the response.
        $response =& new SOAP_Parser($response, $encoding, $attachments);
        if ($response->fault) {
            $fault =& $this->_raiseSoapFault($response->fault);
            return $fault;
        }

        // Return array of parameters.
        $return =& $response->getResponse();
        $headers =& $response->getHeaders();
        if ($headers) {
            $this->headersIn =& $this->__decodeResponse($headers, false);
        }

        $decoded = &$this->__decodeResponse($return);
        return $decoded;
    }

    function &__decodeResponse(&$response, $shift = true)
    {
        if (!$response) {
            $decoded = null;
            return $decoded;
        }

        // Check for valid response.
        if (PEAR::isError($response)) {
            $fault =& $this->_raiseSoapFault($response);
            return $fault;
        } elseif (!is_a($response, 'soap_value')) {
            $fault =& $this->_raiseSoapFault("Didn't get SOAP_Value object back from client");
            return $fault;
        }

        // Decode to native php datatype.
        $returnArray =& $this->_decode($response);

        // Fault?
        if (PEAR::isError($returnArray)) {
            $fault =& $this->_raiseSoapFault($returnArray);
            return $fault;
        }

        if (is_object($returnArray) &&
            strcasecmp(get_class($returnArray), 'stdClass') == 0) {
            $returnArray = get_object_vars($returnArray);
        }
        if (is_array($returnArray)) {
            if (isset($returnArray['faultcode']) ||
                isset($returnArray['SOAP-ENV:faultcode'])) {
                $faultcode = $faultstring = $faultdetail = $faultactor = '';
                foreach ($returnArray as $k => $v) {
                    if (stristr($k, 'faultcode')) $faultcode = $v;
                    if (stristr($k, 'faultstring')) $faultstring = $v;
                    if (stristr($k, 'detail')) $faultdetail = $v;
                    if (stristr($k, 'faultactor')) $faultactor = $v;
                }
                $fault =& $this->_raiseSoapFault($faultstring, $faultdetail, $faultactor, $faultcode);
                return $fault;
            }
            // Return array of return values.
            if ($shift && count($returnArray) == 1) {
                $decoded = array_shift($returnArray);
                return $decoded;
            }
            return $returnArray;
        }
        return $returnArray;
    }

    function __get_wire()
    {
        if ($this->__options['trace'] > 0 &&
            ($this->__last_request || $this->__last_response)) {
            return "OUTGOING:\n\n" .
                $this->__last_request .
                "\n\nINCOMING\n\n" .
                preg_replace("/></",">\r\n<", $this->__last_response);
        }

        return null;
    }

}

⌨️ 快捷键说明

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