Source for file Disco.php
Documentation is available at Disco.php
* This file contains the code for the DISCO server, providing DISO and WSDL
* 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.
* @author Dmitri Vinogradov <dimitri@vinogradov.de>
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Jan Schneider <jan@horde.org>
* @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';
var $namespaces = array (SCHEMA_WSDL => 'wsdl', SCHEMA_SOAP => 'soap');
|| !get_class($soap_server) == 'soap_server') return;
$this->_service_name = $service_name;
$this->_service_ns = " urn:$service_name";
$this->_service_desc = $service_desc;
$this->host = isset ($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
$this->_generate_DISCO ();
function _generate_DISCO ()
$this->_disco['disco:discovery']['attr']['xmlns:disco'] = SCHEMA_DISCO;
$this->_disco['disco:discovery']['scl:contractRef']['attr']['ref'] =
? 'https://' . $this->host . $_SERVER['PHP_SELF'] . '?wsdl'
: 'http://' . $this->host . $_SERVER['PHP_SELF'] . '?wsdl';
$this->_generate_DISCO_XML ($this->_disco);
function _generate_WSDL ()
// need to get: typens, xsd & SOAP-ENC
$this->namespaces[$flipped[SOAP_BASE ::SOAPENCPrefix ()]] = SOAP_BASE ::SOAPENCPrefix ();
$this->_wsdl['definitions']['attr']['name'] = $this->_service_name;
$this->_wsdl['definitions']['attr']['targetNamespace'] = $this->_service_ns;
$this->_wsdl['definitions']['attr']['xmlns:' . $prefix] = $ns;
$this->_wsdl['definitions']['attr']['xmlns'] = SCHEMA_WSDL;
// Import namespaces. Seems to not work yet: wsdl.exe fom .NET can't
// handle imported complete wsdl-definitions.
foreach ($this->import_ns as $_ns => $_location) {
$this->_wsdl['definitions']['import'][$i]['attr']['location'] = $_location;
$this->_wsdl['definitions']['import'][$i]['attr']['namespace'] = $_ns;
$this->_wsdl['definitions']['types']['attr']['xmlns']= 'http://schemas.xmlsoap.org/wsdl/';
$this->_wsdl['definitions']['types']['schema']=array ();
// Placeholder for messages
$this->_wsdl['definitions']['message'] = array ();
$this->_portname = $this->_service_name . 'Port';
$this->_wsdl['definitions']['portType']['attr']['name'] = $this->_portname;
$this->_bindingname = $this->_service_name . 'Binding';
$this->_wsdl['definitions']['binding']['attr']['name'] = $this->_bindingname;
$this->_wsdl['definitions']['binding']['attr']['type'] = 'tns:' . $this->_portname;
$this->_wsdl['definitions']['binding']['soap:binding']['attr']['style'] = 'rpc';
$this->_wsdl['definitions']['binding']['soap:binding']['attr']['transport'] = SCHEMA_SOAP_HTTP;
$this->_wsdl['definitions']['service']['attr']['name'] = $this->_service_name . 'Service';
$this->_wsdl['definitions']['service']['documentation']['attr'] = '';
$this->_wsdl['definitions']['service']['documentation'] = htmlentities($this->_service_desc);
$this->_wsdl['definitions']['service']['port']['attr']['name'] = $this->_portname;
$this->_wsdl['definitions']['service']['port']['attr']['binding'] = 'tns:' . $this->_bindingname;
$this->_wsdl['definitions']['service']['port']['soap:address']['attr']['location'] =
? 'https://' . $this->host . $_SERVER['PHP_SELF']
: 'http://' . $this->host . $_SERVER['PHP_SELF'];
$dc = count($dispatch_keys);
for ($di = 0; $di < $dc; $di++ ) {
$namespace = $dispatch_keys[$di];
$namespace_objects = & $this->soap_server->dispatch_objects [$namespace];
$oc = count($namespace_objects);
for ($oi = 0; $oi < $oc; $oi++ ) {
$object = $namespace_objects[$oi];
$this->_generate_WSDL_XML ();
function &_getSchema ($namespace)
$c = count($this->_wsdl['definitions']['types']['schema']);
for($i = 0; $i < $c; $i++ ) {
if ($this->_wsdl['definitions']['types']['schema'][$i]['attr']['targetNamespace'] == $namespace) {
return $this->_wsdl['definitions']['types']['schema'][$i];
// don't have this namespace
$schema['attr'] = array ();
$schema['complexType'] = array ();
$schema['attr']['targetNamespace'] = $namespace;
$this->_wsdl['definitions']['types']['schema'][] = & $schema;
foreach ($map as $_type_name => $_type_def) {
list ($typens,$type) = $this->_getTypeNs ($_type_name);
// cannot add to xsd, lets use method_namespace
if (!$this->_ifComplexTypeExists ($schema['complexType'], $type)) {
$ctype = & $schema['complexType'][];
$ctype['attr']['name'] = $type;
foreach ($_type_def as $_varname => $_vartype) {
list ($_vartypens,$_vartype) = $this->_getTypeNs ($_vartype);
$ctype['all']['attr'] = '';
$el = & $ctype['all']['element'][];
$el['attr']['name'] = $_varname;
$el['attr']['type'] = $_vartypens . ':' . $_vartype;
$ctype['complexContent']['attr'] = '';
$ctype['complexContent']['restriction']['attr']['base'] = SOAP_BASE ::SOAPENCPrefix (). ':Array';
foreach ($_vartype as $array_type) {
list ($_vartypens, $_vartype) = $this->_getTypeNs ($array_type);
$ctype['complexContent']['restriction']['attribute']['attr']['ref'] = SOAP_BASE ::SOAPENCPrefix (). ':arrayType';
$ctype['complexContent']['restriction']['attribute']['attr']['wsdl:arrayType'] = $_vartypens . ':' . $_vartype . '[]';
foreach ($map as $method_name => $method_types) {
$method_namespace = $method_types['namespace'];
$method_namespace = $namespace;
$input_message = array ('attr' => array ('name' => $method_name . 'Request'));
if (isset ($method_types['in']) && is_array($method_types['in'])) {
foreach ($method_types['in'] as $name => $type) {
list ($typens, $type) = $this->_getTypeNs ($type);
$part['attr']['name'] = $name;
$part['attr']['type'] = $typens . ':' . $type;
$input_message['part'][] = $part;
$this->_wsdl['definitions']['message'][] = $input_message;
$output_message = array ('attr' => array ('name' => $method_name . 'Response'));
if (isset ($method_types['out']) && is_array($method_types['out'])) {
foreach ($method_types['out'] as $name => $type) {
list ($typens, $type) = $this->_getTypeNs ($type);
$part['attr']['name'] = $name;
$part['attr']['type'] = $typens . ':' . $type;
$output_message['part'][] = $part;
$this->_wsdl['definitions']['message'][] = $output_message;
$operation['attr']['name'] = $method_name;
$operation['input']['attr']['message'] = 'tns:' . $input_message['attr']['name'];
$operation['output']['attr']['message'] = 'tns:' . $output_message['attr']['name'];
$this->_wsdl['definitions']['portType']['operation'][] = $operation;
$binding['attr']['name'] = $method_name;
$action = $method_namespace . '#' . ($classname ? $classname . '#' : '') . $method_name;
$binding['soap:operation']['attr']['soapAction'] = $action;
$binding['input']['attr'] = '';
$binding['input']['soap:body']['attr']['use'] = 'encoded';
$binding['input']['soap:body']['attr']['namespace'] = $method_namespace;
$binding['output']['attr'] = '';
$binding['output']['soap:body']['attr']['use'] = 'encoded';
$binding['output']['soap:body']['attr']['namespace'] = $method_namespace;
$this->_wsdl['definitions']['binding']['operation'][] = $binding;
function _generate_DISCO_XML ($disco_array)
$disco = '<?xml version="1.0"?>';
foreach ($disco_array as $key => $val) {
$disco .= $this->_arrayToNode ($key,$val);
function _generate_WSDL_XML ()
$wsdl = '<?xml version="1.0"?>';
foreach ($this->_wsdl as $key => $val) {
$wsdl .= $this->_arrayToNode ($key, $val);
function _arrayToNode ($node_name = '', $array)
// we have a node if there's key 'attr'
$return .= " <$node_name";
foreach ($array['attr'] as $attr_name => $attr_value) {
$return .= " $attr_name=\"$attr_value\"";
// unset 'attr' and proceed other childs...
foreach ($array as $child_node_name => $child_node_value) {
$return .= $i == 0 ? ">\n" : '';
$return .= $this->_arrayToNode ($child_node_name,$child_node_value);
$return .= " </$node_name>\n";
// we have no 'attr' key in array - so it's list of nodes with
foreach ($array as $child_node_name => $child_node_value) {
$return .= $this->_arrayToNode ($node_name,$child_node_value);
// $array is not an array
$return .= " <$node_name>$array</$node_name>\n";
$return .= " <$node_name />\n";
function _getTypeNs ($type)
if (isset ($m[1 ][0 ]) && $m[1 ][0 ] != '') {
$this->_wsdl['definitions']['attr']['xmlns:' . $ns_pref] = $m[1 ][0 ];
return array ($typens,$type);
function _ifComplexTypeExists ($typesArray, $type_name)
foreach ($typesArray as $type_data) {
if ($type_data['attr']['name'] == $type_name) {
Documentation generated on Mon, 04 Aug 2008 20:00:17 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|