📄 wsdl.php
字号:
<?php
/**
* This file contains the code for dealing with WSDL access and services.
*
* 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/Base.php';
require_once 'SOAP/Fault.php';
require_once 'HTTP/Request.php';
define('WSDL_CACHE_MAX_AGE', 43200);
define('WSDL_CACHE_USE', 0); // set to zero to turn off caching
/**
* This class parses WSDL files, and can be used by SOAP::Client to properly
* register soap values for services.
*
* Originally based on SOAPx4 by Dietrich Ayala
* http://dietrich.ganx4.com/soapx4
*
* @todo
* - add wsdl caching
* - refactor namespace handling ($namespace/$ns)
* - implement IDL type syntax declaration so we can generate WSDL
*
* @access public
* @package SOAP
* @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates
* @author Dietrich Ayala <dietrich@ganx4.com> Original Author
*/
class SOAP_WSDL extends SOAP_Base
{
var $tns = null;
var $definition = array();
var $namespaces = array();
var $ns = array();
var $xsd = SOAP_XML_SCHEMA_VERSION;
var $complexTypes = array();
var $elements = array();
var $messages = array();
var $portTypes = array();
var $bindings = array();
var $imports = array();
var $services = array();
var $service = '';
var $uri = '';
var $docs = false;
/**
* Proxy parameters
*
* @var array
*/
var $proxy = null;
var $trace = 0;
/**
* Use WSDL cache.
*
* @var boolean
*/
var $cacheUse = null;
/**
* Cache max lifetime (in seconds).
*
* @var integer
*/
var $cacheMaxAge = null;
/**
* Class to use for WSDL parsing. Can be overridden for special cases,
* subclasses, etc.
*
* @var string
*/
var $wsdlParserClass = 'SOAP_WSDL_Parser';
/**
* SOAP_WSDL constructor.
*
* @param string $wsdl_uri URL to WSDL file.
* @param array $proxy Contains options for HTTP_Request class
* @see HTTP_Request.
* @param boolean $cacheUse Use WSDL caching. Defaults to false.
* @param integer $cacheMaxAge Cache max lifetime (in seconds).
* @param boolean $docs Parse documentation in the WSDL? Defaults
* to false.
*
* @access public
*/
function SOAP_WSDL($wsdl_uri = false,
$proxy = array(),
$cacheUse = WSDL_CACHE_USE,
$cacheMaxAge = WSDL_CACHE_MAX_AGE,
$docs = false)
{
parent::SOAP_Base('WSDL');
$this->uri = $wsdl_uri;
$this->proxy = $proxy;
$this->cacheUse = $cacheUse;
$this->cacheMaxAge = $cacheMaxAge;
$this->docs = $docs;
if ($wsdl_uri) {
if (!PEAR::isError($this->parseURL($wsdl_uri))) {
reset($this->services);
$this->service = key($this->services);
}
}
}
function set_service($service)
{
if (array_key_exists($service, $this->services)) {
$this->service = $service;
}
}
/**
* @deprecated use parseURL instead
*/
function parse($wsdl_uri, $proxy = array())
{
$this->parseURL($wsdl_uri, $proxy);
}
/**
* Fills the WSDL array tree with data from a WSDL file.
*
* @param string $wsdl_uri URL to WSDL file.
* @param array $proxy Contains options for HTTP_Request class
* @see HTTP_Request.
*/
function parseURL($wsdl_uri, $proxy = array())
{
$parser =& new $this->wsdlParserClass($wsdl_uri, $this, $this->docs);
if ($parser->fault) {
$this->_raiseSoapFault($parser->fault);
}
}
/**
* Fills the WSDL array tree with data from one or more PHP class objects.
*
* @param mixed $wsdl_obj An object or array of objects to add to
* the internal WSDL tree.
* @param string $targetNamespace The target namespace of schema types
* etc.
* @param string $service_name Name of the WSDL service.
* @param string $service_desc Optional description of the WSDL
* service.
*/
function parseObject(&$wsdl_obj, $targetNamespace, $service_name,
$service_desc = '')
{
$parser =& new SOAP_WSDL_ObjectParser($wsdl_obj, $this,
$targetNamespace, $service_name,
$service_desc);
if ($parser->fault) {
$this->_raiseSoapFault($parser->fault);
}
}
function getEndpoint($portName)
{
if ($this->__isfault()) {
return $this->__getfault();
}
return (isset($this->services[$this->service]['ports'][$portName]['address']['location']))
? $this->services[$this->service]['ports'][$portName]['address']['location']
: $this->_raiseSoapFault("No endpoint for port for $portName", $this->uri);
}
function _getPortName($operation, $service)
{
if (isset($this->services[$service]['ports'])) {
$ports = $this->services[$service]['ports'];
foreach ($ports as $port => $portAttrs) {
$type = $ports[$port]['type'];
if ($type == 'soap' &&
isset($this->bindings[$portAttrs['binding']]['operations'][$operation])) {
return $port;
}
}
}
return null;
}
/**
* Finds the name of the first port that contains an operation of name
* $operation. Always returns a SOAP portName.
*/
function getPortName($operation, $service = null)
{
if ($this->__isfault()) {
return $this->__getfault();
}
if (!$service) {
$service = $this->service;
}
if (isset($this->services[$service]['ports'])) {
if ($portName = $this->_getPortName($operation, $service)) {
return $portName;
}
}
// Try any service in the WSDL.
foreach ($this->services as $serviceName => $service) {
if (isset($this->services[$serviceName]['ports'])) {
if ($portName = $this->_getPortName($operation, $serviceName)) {
$this->service = $serviceName;
return $portName;
}
}
}
return $this->_raiseSoapFault("No operation $operation in WSDL.", $this->uri);
}
function getOperationData($portName, $operation)
{
if ($this->__isfault()) {
return $this->__getfault();
}
if (!isset($this->services[$this->service]['ports'][$portName]['binding']) ||
!($binding = $this->services[$this->service]['ports'][$portName]['binding'])) {
return $this->_raiseSoapFault("No binding for port $portName in WSDL.", $this->uri);
}
// Get operation data from binding.
if (is_array($this->bindings[$binding]['operations'][$operation])) {
$opData = $this->bindings[$binding]['operations'][$operation];
}
// get operation data from porttype
$portType = $this->bindings[$binding]['type'];
if (!$portType) {
return $this->_raiseSoapFault("No port type for binding $binding in WSDL.", $this->uri);
}
if (is_array($type = $this->portTypes[$portType][$operation])) {
if (isset($type['parameterOrder'])) {
$opData['parameterOrder'] = $type['parameterOrder'];
}
$opData['input'] = array_merge($opData['input'], $type['input']);
$opData['output'] = array_merge($opData['output'], $type['output']);
}
if (!$opData)
return $this->_raiseSoapFault("No operation $operation for port $portName in WSDL.", $this->uri);
$opData['parameters'] = false;
if (isset($this->bindings[$binding]['operations'][$operation]['input']['namespace']))
$opData['namespace'] = $this->bindings[$binding]['operations'][$operation]['input']['namespace'];
// Message data from messages.
$inputMsg = $opData['input']['message'];
if (is_array($this->messages[$inputMsg])) {
foreach ($this->messages[$inputMsg] as $pname => $pattrs) {
if ($opData['style'] == 'document' &&
$opData['input']['use'] == 'literal' &&
$pname == 'parameters') {
$opData['parameters'] = true;
$opData['namespace'] = $this->namespaces[$pattrs['namespace']];
$el = $this->elements[$pattrs['namespace']][$pattrs['type']];
if (isset($el['elements'])) {
foreach ($el['elements'] as $elname => $elattrs) {
$opData['input']['parts'][$elname] = $elattrs;
}
}
} else {
$opData['input']['parts'][$pname] = $pattrs;
}
}
}
$outputMsg = $opData['output']['message'];
if (is_array($this->messages[$outputMsg])) {
foreach ($this->messages[$outputMsg] as $pname => $pattrs) {
if ($opData['style'] == 'document' &&
$opData['output']['use'] == 'literal' &&
$pname == 'parameters') {
$el = $this->elements[$pattrs['namespace']][$pattrs['type']];
if (isset($el['elements'])) {
foreach ($el['elements'] as $elname => $elattrs) {
$opData['output']['parts'][$elname] = $elattrs;
}
}
} else {
$opData['output']['parts'][$pname] = $pattrs;
}
}
}
return $opData;
}
function matchMethod(&$operation)
{
if ($this->__isfault()) {
return $this->__getfault();
}
// Overloading lowercases function names :(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -