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

📄 client.php

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
/**
 * This file contains the code for the SOAP client.
 *
 * PHP versions 4 and 5
 *
 * LICENSE: This source file is subject to version 2.02 of the PHP license,
 * that is bundled with this package in the file LICENSE, and is available at
 * through the world-wide-web at http://www.php.net/license/2_02.txt.  If you
 * did not receive a copy of the PHP license and are unable to obtain it
 * through the world-wide-web, please send a note to license@php.net so we can
 * mail you a copy immediately.
 *
 * @category   Web Services
 * @package    SOAP
 * @author     Dietrich Ayala <dietrich@ganx4.com> Original Author
 * @author     Shane Caraveo <Shane@Caraveo.com>   Port to PEAR and more
 * @author     Chuck Hagenbuch <chuck@horde.org>   Maintenance
 * @author     Jan Schneider <jan@horde.org>       Maintenance
 * @copyright  2003-2005 The PHP Group
 * @license    http://www.php.net/license/2_02.txt  PHP License 2.02
 * @link       http://pear.php.net/package/SOAP
 */

require_once 'SOAP/Value.php';
require_once 'SOAP/Base.php';
require_once 'SOAP/Transport.php';
require_once 'SOAP/WSDL.php';
require_once 'SOAP/Fault.php';
require_once 'SOAP/Parser.php';

// Arnaud: the following code was taken from DataObject and adapted to suit

// this will be horrifically slow!!!!
// NOTE: Overload SEGFAULTS ON PHP4 + Zend Optimizer
// these two are BC/FC handlers for call in PHP4/5

if (!class_exists('SOAP_Client_Overload')) {
    if (substr(phpversion(), 0, 1) == 5) {
        class SOAP_Client_Overload extends SOAP_Base {
            function __call($method, $args)
            {
                $return = null;
                $this->_call($method, $args, $return);
                return $return;
            }
        }
    } else {
        if (!function_exists('clone')) {
            eval('function clone($t) { return $t; }');
        }
        eval('
            class SOAP_Client_Overload extends SOAP_Base {
                function __call($method, $args, &$return)
                {
                    return $this->_call($method, $args, $return);
                }
            }');
    }
}

/**
 * SOAP Client Class
 *
 * This class is the main interface for making soap requests.
 *
 * basic usage:<code>
 *   $soapclient = new SOAP_Client( string path [ , boolean wsdl] );
 *   echo $soapclient->call( string methodname [ , array parameters] );
 * </code>
 *
 * Originally based on SOAPx4 by Dietrich Ayala
 * http://dietrich.ganx4.com/soapx4
 *
 * @access   public
 * @package  SOAP
 * @author   Shane Caraveo <shane@php.net> Conversion to PEAR and updates
 * @author   Stig Bakken <ssb@fast.no> Conversion to PEAR
 * @author   Dietrich Ayala <dietrich@ganx4.com> Original Author
 */
class SOAP_Client extends SOAP_Client_Overload
{
    /**
     * Communication endpoint.
     *
     * Currently the following transport formats are supported:
     *  - HTTP
     *  - SMTP
     *
     * Example endpoints:
     *   http://www.example.com/soap/server.php
     *   https://www.example.com/soap/server.php
     *   mailto:soap@example.com
     *
     * @see  SOAP_Client()
     * @var $_endpoint string
     */
    var $_endpoint = '';

    /**
     * The SOAP PORT name that is used by the client.
     *
     * @var $_portName string
     */
    var $_portName = '';

    /**
     * Endpoint type e.g. 'wdsl'.
     *
     * @var $__endpointType string
     */
    var $__endpointType = '';

    /**
     * The received xml.
     *
     * @var $xml string
     */
    var $xml;

    /**
     * The outgoing and incoming data stream for debugging.
     *
     * @var $wire string
     */
    var $wire;
    var $__last_request = null;
    var $__last_response = null;

    /**
     * Options.
     *
     * @var $__options array
     */
    var $__options = array('trace'=>0);

    /**
     * The character encoding used for XML parser, etc.
     *
     * @var $_encoding string
     */
    var $_encoding = SOAP_DEFAULT_ENCODING;

    /**
     * The array of SOAP_Headers that we are sending.
     *
     * @var $headersOut array
     */
    var $headersOut = null;

    /**
     * The headers we recieved back in the response.
     *
     * @var $headersIn array
     */
    var $headersIn = null;

    /**
     * Options for the HTTP_Request class (see HTTP/Request.php).
     *
     * @var $__proxy_params array
     */
    var $__proxy_params = array();

    var $_soap_transport = null;

    /**
     * Constructor.
     *
     * @access public
     *
     * @param string $endpoint     An URL.
     * @param boolean $wsdl        Whether the endpoint is a WSDL file.
     * @param string $portName
     * @param array $proxy_params  Options for the HTTP_Request class (see
     *                             HTTP/Request.php)
     */
    function SOAP_Client($endpoint, $wsdl = false, $portName = false,
                         $proxy_params = array())
    {
        parent::SOAP_Base('Client');

        $this->_endpoint = $endpoint;
        $this->_portName = $portName;
        $this->__proxy_params = $proxy_params;

        // This hack should perhaps be removed as it might cause unexpected
        // behaviour.
        $wsdl = $wsdl
            ? $wsdl
            : strtolower(substr($endpoint, -4)) == 'wsdl';

        // make values
        if ($wsdl) {
            $this->__endpointType = 'wsdl';
            // instantiate wsdl class
            $this->_wsdl =& new SOAP_WSDL($this->_endpoint,
                                          $this->__proxy_params);
            if ($this->_wsdl->fault) {
                $this->_raiseSoapFault($this->_wsdl->fault);
            }
        }
    }

    function _reset()
    {
        $this->xml = null;
        $this->wire = null;
        $this->__last_request = null;
        $this->__last_response = null;
        $this->headersIn = null;
        $this->headersOut = null;
    }

    /**
     * Sets the character encoding.
     *
     * Limited to 'UTF-8', 'US_ASCII' and 'ISO-8859-1'.
     *
     * @access public
     *
     * @param string encoding
     *
     * @return mixed  SOAP_Fault on error.
     */
    function setEncoding($encoding)
    {
        if (in_array($encoding, $this->_encodings)) {
            $this->_encoding = $encoding;
            return;
        }
        return $this->_raiseSoapFault('Invalid Encoding');
    }

    /**
     * Adds a header to the envelope.
     *
     * @access public
     *
     * @param SOAP_Header $soap_value  A SOAP_Header or an array with the
     *                                 elements 'name', 'namespace',
     *                                 'mustunderstand', and 'actor' to send
     *                                 as a header.
     */
    function addHeader(&$soap_value)
    {
        // Add a new header to the message.
        if (is_a($soap_value, 'SOAP_Header')) {
            $this->headersOut[] =& $soap_value;
        } elseif (is_array($soap_value)) {
            // name, value, namespace, mustunderstand, actor
            $this->headersOut[] =& new SOAP_Header($soap_value[0],
                                                   null,
                                                   $soap_value[1],
                                                   $soap_value[2],
                                                   $soap_value[3]);;
        } else {
            $this->_raiseSoapFault('Invalid parameter provided to addHeader().  Must be an array or a SOAP_Header.');
        }
    }

    /**
     * Calls a method on the SOAP endpoint.
     *
     * The namespace parameter is overloaded to accept an array of options
     * that can contain data necessary for various transports if it is used as
     * an array, it MAY contain a namespace value and a soapaction value.  If
     * it is overloaded, the soapaction parameter is ignored and MUST be
     * placed in the options array.  This is done to provide backwards
     * compatibility with current clients, but may be removed in the future.
     * The currently supported values are:<pre>
     *   namespace
     *   soapaction
     *   timeout (HTTP socket timeout)
     *   transfer-encoding (SMTP, Content-Transfer-Encoding: header)
     *   from (SMTP, From: header)
     *   subject (SMTP, Subject: header)
     *   headers (SMTP, hash of extra SMTP headers)
     * </pre>
     *
     * @access public
     *
     * @param string $method           The method to call.
     * @param array $params            The method parameters.
     * @param string|array $namespace  Namespace or hash with options.
     * @param string $soapAction
     *
     * @return mixed  The method result or a SOAP_Fault on error.
     */
    function &call($method, &$params, $namespace = false, $soapAction = false)
    {
        $this->headersIn = null;
        $this->__last_request = null;
        $this->__last_response = null;
        $this->wire = null;
        $this->xml = null;

        $soap_data =& $this->__generate($method, $params, $namespace, $soapAction);
        if (PEAR::isError($soap_data)) {
            $fault =& $this->_raiseSoapFault($soap_data);
            return $fault;
        }

        // __generate() may have changed the endpoint if the WSDL has more
        // than one service, so we need to see if we need to generate a new
        // transport to hook to a different URI.  Since the transport protocol
        // can also change, we need to get an entirely new object.  This could
        // probably be optimized.
        if (!$this->_soap_transport ||
            $this->_endpoint != $this->_soap_transport->url) {
            $this->_soap_transport =& SOAP_Transport::getTransport($this->_endpoint);
            if (PEAR::isError($this->_soap_transport)) {
                $fault =& $this->_soap_transport;
                $this->_soap_transport = null;
                $fault =& $this->_raiseSoapFault($fault);
                return $fault;
            }
        }
        $this->_soap_transport->encoding = $this->_encoding;

        // Send the message.
        $transport_options = array_merge_recursive($this->__proxy_params,
                                                   $this->__options);
        $this->xml = $this->_soap_transport->send($soap_data, $transport_options);

        // Save the wire information for debugging.
        if ($this->__options['trace'] > 0) {
            $this->__last_request =& $this->_soap_transport->outgoing_payload;
            $this->__last_response =& $this->_soap_transport->incoming_payload;
            $this->wire = $this->__get_wire();
        }
        if ($this->_soap_transport->fault) {
            $fault =& $this->_raiseSoapFault($this->xml);
            return $fault;
        }

        $this->__attachments =& $this->_soap_transport->attachments;
        $this->__result_encoding = $this->_soap_transport->result_encoding;

        if (isset($this->__options['result']) &&
            $this->__options['result'] != 'parse') {
            return $this->xml;
        }

        $result = &$this->__parse($this->xml, $this->__result_encoding, $this->__attachments);

        return $result;
    }

    /**
     * Sets an option to use with the transport layers.
     *
     * For example:
     * <code>
     * $soapclient->setOpt('curl', CURLOPT_VERBOSE, 1)
     * </code>
     * to pass a specific option to curl if using an SSL connection.
     *
     * @access public
     *
     * @param string $category  Category to which the option applies or option
     *                          name.
     * @param string $option    An option name if $category is a category name,
     *                          an option value if $category is an option name.
     * @param string $value     An option value if $category is a category
     *                          name.
     */
    function setOpt($category, $option, $value = null)

⌨️ 快捷键说明

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