📄 wsdl.php
字号:
if (isset($_argtype['element'])) {
// Element argument.
$comments .= $this->_elementArg($args, $argarray, $_argtype, $_argtype['type']);
} else {
// Complex type argument.
$comments .= $this->_complexTypeArg($args, $argarray, $_argtype, $_argname);
}
}
}
}
}
// Validate entries.
// Operation names are function names, so try to make sure it's
// legal. This could potentially cause collisions, but let's try
// to make everything callable and see how many problems that
// causes.
$opname_php = preg_replace('/[ .\-\(\)]+/', '_', $opname);
if (!$this->_validateString($opname_php)) {
return null;
}
if ($argarray) {
$argarray = "array($argarray)";
} else {
$argarray = 'null';
}
$class .= " function &$opname_php($args)\n {\n$comments$wrappers" .
" \$result = \$this->call('$opname',\n" .
" \$v = $argarray,\n" .
" array('namespace' => '$namespace',\n" .
" 'soapaction' => '$soapaction',\n" .
" 'style' => '$opstyle',\n" .
" 'use' => '$use'" .
($this->trace?",\n 'trace' => 1" : '') . "));\n" .
" return \$result;\n" .
" }\n";
}
$class .= "}\n";
return $class;
}
function generateAllProxies()
{
$proxycode = '';
foreach (array_keys($this->services[$this->service]['ports']) as $key) {
$port =& $this->services[$this->service]['ports'][$key];
$proxycode .= $this->generateProxyCode($port);
}
return $proxycode;
}
function &getProxy($port = '', $name = '')
{
if ($this->__isfault()) {
$fault =& $this->__getfault();
return $fault;
}
$multiport = count($this->services[$this->service]['ports']) > 1;
if (!$port) {
reset($this->services[$this->service]['ports']);
$port = current($this->services[$this->service]['ports']);
}
if ($multiport || $port) {
$classname = 'WebService_' . $this->service . '_' . $port['name'];
} else {
$classname = 'WebService_' . $this->service;
}
if ($name) {
$classname = $name . '_' . $classname;
}
$classname = preg_replace('/[ .\-\(\)]+/', '_', $classname);
if (!class_exists($classname)) {
$proxy = $this->generateProxyCode($port, $classname);
require_once 'SOAP/Client.php';
eval($proxy);
}
$proxy =& new $classname;
return $proxy;
}
function &_getComplexTypeForElement($name, $namespace)
{
$t = null;
if (isset($this->ns[$namespace]) &&
isset($this->elements[$this->ns[$namespace]][$name]['type'])) {
$type = $this->elements[$this->ns[$namespace]][$name]['type'];
$ns = $this->elements[$this->ns[$namespace]][$name]['namespace'];
if (isset($this->complexTypes[$ns][$type])) {
$t = $this->complexTypes[$ns][$type];
}
}
return $t;
}
function getComplexTypeNameForElement($name, $namespace)
{
$t = $this->_getComplexTypeForElement($name, $namespace);
if ($t) {
return $t['name'];
}
return null;
}
function getComplexTypeChildType($ns, $name, $child_ns, $child_name)
{
// is the type an element?
$t = $this->_getComplexTypeForElement($name, $ns);
if ($t) {
// no, get it from complex types directly
if (isset($t['elements'][$child_name]['type']))
return $t['elements'][$child_name]['type'];
}
return null;
}
function getSchemaType($type, $name, $type_namespace)
{
// see if it's a complex type so we can deal properly with
// SOAPENC:arrayType.
if ($name && $type) {
// XXX TODO:
// look up the name in the wsdl and validate the type.
foreach ($this->complexTypes as $ns => $types) {
if (array_key_exists($type, $types)) {
if (array_key_exists('type', $types[$type])) {
list($arraytype_ns, $arraytype, $array_depth) = isset($types[$type]['arrayType'])?
$this->_getDeepestArrayType($types[$type]['namespace'], $types[$type]['arrayType'])
: array($this->namespaces[$types[$type]['namespace']], null, 0);
return array($types[$type]['type'], $arraytype, $arraytype_ns, $array_depth);
}
if (array_key_exists('arrayType', $types[$type])) {
list($arraytype_ns, $arraytype, $array_depth) =
$this->_getDeepestArrayType($types[$type]['namespace'], $types[$type]['arrayType']);
return array('Array', $arraytype, $arraytype_ns, $array_depth);
}
if (array_key_exists('elements', $types[$type]) &&
array_key_exists($name, $types[$type]['elements'])) {
$type = $types[$type]['elements']['type'];
return array($type, null, $this->namespaces[$types[$type]['namespace']], null);
}
}
}
}
if ($type && $type_namespace) {
$arrayType = null;
// XXX TODO:
// this code currently handles only one way of encoding array types in wsdl
// need to do a generalized function to figure out complex types
$p = $this->ns[$type_namespace];
if ($p &&
array_key_exists($p, $this->complexTypes) &&
array_key_exists($type, $this->complexTypes[$p])) {
if ($arrayType = $this->complexTypes[$p][$type]['arrayType']) {
$type = 'Array';
} elseif ($this->complexTypes[$p][$type]['order']=='sequence' &&
array_key_exists('elements', $this->complexTypes[$p][$type])) {
reset($this->complexTypes[$p][$type]['elements']);
// assume an array
if (count($this->complexTypes[$p][$type]['elements']) == 1) {
$arg = current($this->complexTypes[$p][$type]['elements']);
$arrayType = $arg['type'];
$type = 'Array';
} else {
foreach ($this->complexTypes[$p][$type]['elements'] as $element) {
if ($element['name'] == $type) {
$arrayType = $element['type'];
$type = $element['type'];
}
}
}
} else {
$type = 'Struct';
}
return array($type, $arrayType, $type_namespace, null);
}
}
return array(null, null, null, null);
}
/**
* Recurse through the WSDL structure looking for the innermost array type
* of multi-dimensional arrays.
*
* Takes a namespace prefix and a type, which can be in the form 'type' or
* 'type[]', and returns the full namespace URI, the type of the most
* deeply nested array type found, and the number of levels of nesting.
*
* @access private
* @return mixed array or nothing
*/
function _getDeepestArrayType($nsPrefix, $arrayType)
{
static $trail = array();
$arrayType = ereg_replace('\[\]$', '', $arrayType);
// Protect against circular references XXX We really need to remove
// trail from this altogether (it's very inefficient and in the wrong
// place!) and put circular reference checking in when the WSDL info
// is generated in the first place
if (array_search($nsPrefix . ':' . $arrayType, $trail)) {
return array(null, null, -count($trail));
}
if (array_key_exists($nsPrefix, $this->complexTypes) &&
array_key_exists($arrayType, $this->complexTypes[$nsPrefix]) &&
array_key_exists('arrayType', $this->complexTypes[$nsPrefix][$arrayType])) {
$trail[] = $nsPrefix . ':' . $arrayType;
$result = $this->_getDeepestArrayType($this->complexTypes[$nsPrefix][$arrayType]['namespace'],
$this->complexTypes[$nsPrefix][$arrayType]['arrayType']);
return array($result[0], $result[1], $result[2] + 1);
}
return array($this->namespaces[$nsPrefix], $arrayType, 0);
}
}
class SOAP_WSDL_Cache extends SOAP_Base
{
// Cache settings
/**
* Use WSDL cache
*
* @var boolean
*/
var $_cacheUse = null;
/**
* Cache max lifetime (in seconds)
*
* @var int
*/
var $_cacheMaxAge = null;
/**
* SOAP_WSDL_Cache constructor
*
* @param boolean use caching
* @param int cache max lifetime (in seconds)
* @access public
*/
function SOAP_WSDL_Cache($cacheUse = WSDL_CACHE_USE,
$cacheMaxAge = WSDL_CACHE_MAX_AGE)
{
parent::SOAP_Base('WSDLCACHE');
$this->_cacheUse = $cacheUse;
$this->_cacheMaxAge = $cacheMaxAge;
}
/**
* _cacheDir
* return the path to the cache, if it doesn't exist, make it
*/
function _cacheDir()
{
$dir = getenv("WSDLCACHE");
if (!$dir) $dir = " ./wsdlcache";
@mkdir($dir, 0700);
return $dir;
}
/**
* Retrieves a file from cache if it exists, otherwise retreive from net,
* add to cache, and return from cache.
*
* @param string URL to WSDL
* @param array proxy parameters
* @param int expected MD5 of WSDL URL
* @access public
* @return string data
*/
function get($wsdl_fname, $proxy_params = array(), $cache = 0)
{
$cachename = $md5_wsdl = $file_data = '';
if ($this->_cacheUse) {
// Try to retrieve WSDL from cache
$cachename = SOAP_WSDL_Cache::_cacheDir() . '/' . md5($wsdl_fname). ' .wsdl';
if (file_exists($cachename)) {
$wf = fopen($cachename, 'rb');
if ($wf) {
// Reading cached file
$file_data = fread($wf, filesize($cachename));
$md5_wsdl = md5($file_data);
fclose($wf);
}
if ($cache) {
if ($cache != $md5_wsdl) {
return $this->_raiseSoapFault('WSDL Checksum error!', $wsdl_fname);
}
} else {
$fi = stat($cachename);
$cache_mtime = $fi[8];
//print cache_mtime, time()
if ($cache_mtime + $this->_cacheMaxAge < time()) {
// expired
$md5_wsdl = ''; // refetch
}
}
}
}
if (!$md5_wsdl) {
// Not cached or not using cache. Retrieve WSDL from URL
// is it a local file?
// this section should be replace by curl at some point
if (!preg_match('/^(https?|file):\/\//', $wsdl_fname)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -