cvs: pear /SOAP Disco.php package.xml

From: Date: Thu, 26 May 2005 22:26:17 +0000
Subject: cvs: pear /SOAP Disco.php package.xml
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-32146@lists.php.net to get a copy of this message
yunosh Thu May 26 18:26:17 2005 EDT Modified files: /pear/SOAP Disco.php package.xml Log: Fix PEAR bug #1657 - create WSDL element in the correct order.

http://cvs.php.net/diff.php/pear/SOAP/Disco.php?r1=1.10&r2=1.11&ty=u Index: pear/SOAP/Disco.php diff -u pear/SOAP/Disco.php:1.10 pear/SOAP/Disco.php:1.11 --- pear/SOAP/Disco.php:1.10 Thu Mar 10 18:16:37 2005 +++ pear/SOAP/Disco.php Thu May 26 18:26:17 2005 @@ -16,12 +16,12 @@ // | Author: Dmitri Vinogradov <dimitri@vinogradov.de> | // +----------------------------------------------------------------------+ // -// $Id: Disco.php,v 1.10 2005/03/10 23:16:37 yunosh Exp $ +// $Id: Disco.php,v 1.11 2005/05/26 22:26:17 yunosh Exp $ require_once 'SOAP/Base.php'; -class SOAP_DISCO_Server extends SOAP_Base_Object -{ +class SOAP_DISCO_Server extends SOAP_Base_Object { + var $namespaces = array(SCHEMA_WSDL => 'wsdl', SCHEMA_SOAP => 'soap'); var $import_ns = array(); var $wsdl = ''; @@ -36,7 +36,8 @@ var $soap_server = NULL; - function SOAP_DISCO_Server($soap_server, $service_name, $service_desc = '', $import_ns = null) + function SOAP_DISCO_Server($soap_server, $service_name, $service_desc = '', + $import_ns = null) { parent::SOAP_Base_Object('Server'); @@ -48,7 +49,7 @@ $this->_service_desc = $service_desc; $this->import_ns = isset($import_ns) ? $import_ns : $this->import_ns; $this->soap_server = $soap_server; - $this->host = isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:'localhost'; + $this->host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost'; } function getDISCO() @@ -65,30 +66,30 @@ function _generate_DISCO() { - # DISCO + // DISCO $this->_disco['disco:discovery']['attr']['xmlns:disco'] = SCHEMA_DISCO; $this->_disco['disco:discovery']['attr']['xmlns:scl'] = SCHEMA_DISCO_SCL; $this->_disco['disco:discovery']['scl:contractRef']['attr']['ref'] = - (array_key_exists('HTTPS',$_SERVER) && $_SERVER['HTTPS']=='on') - ? 'https://' . $this->host . $_SERVER['PHP_SELF'] . '?wsdl' - : 'http://' . $this->host . $_SERVER['PHP_SELF'] . '?wsdl'; + (array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] == 'on') + ? 'https://' . $this->host . $_SERVER['PHP_SELF'] . '?wsdl' + : 'http://' . $this->host . $_SERVER['PHP_SELF'] . '?wsdl'; - # generate disco xml + // generate disco xml $this->_generate_DISCO_XML($this->_disco); } function _generate_WSDL() { - # WSDL + // WSDL if (is_array($this->soap_server->_namespaces)) { - # need to get: typens, xsd & SOAP-ENC + // need to get: typens, xsd & SOAP-ENC $flipped = array_flip($this->soap_server->_namespaces); $this->namespaces[$this->_service_ns] = 'tns'; $this->namespaces[$flipped['xsd']] = 'xsd'; $this->namespaces[$flipped['SOAP-ENC']] = 'SOAP-ENC'; } - # DEFINITIONS + // DEFINITIONS $this->_wsdl['definitions']['attr']['name'] = $this->_service_name; $this->_wsdl['definitions']['attr']['targetNamespace'] = $this->_service_ns; foreach ($this->namespaces as $ns => $prefix) { @@ -96,10 +97,9 @@ } $this->_wsdl['definitions']['attr']['xmlns'] = SCHEMA_WSDL; - # import namespaces - # seems to not work yet: wsdl.exe fom .NET cant handle imported complete wsdl-definitions - # - if (count($this->import_ns)>0) { + // Import namespaces. Seems to not work yet: wsdl.exe fom .NET can't + // handle imported complete wsdl-definitions. + if (count($this->import_ns)) { $i = 0; foreach ($this->import_ns as $_ns => $_location) { $this->_wsdl['definitions']['import'][$i]['attr']['location'] = $_location; @@ -109,77 +109,89 @@ } $this->_wsdl['definitions']['types']['attr']['xmlns']='http://schemas.xmlsoap.org/wsdl/'; $this->_wsdl['definitions']['types']['schema']=array(); - # PORTTYPE-NAME + + // Placeholder for messages + $this->_wsdl['definitions']['message'] = array(); + + // PORTTYPE-NAME $this->_portname = $this->_service_name . 'Port'; $this->_wsdl['definitions']['portType']['attr']['name'] = $this->_portname; - # BINDING-NAME + // BINDING-NAME $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; - # SERVICE + // SERVICE $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'] = - (array_key_exists('HTTPS',$_SERVER) && $_SERVER['HTTPS']=='on') - ? 'https://' . $this->host . $_SERVER['PHP_SELF'] - : 'http://' . $this->host . $_SERVER['PHP_SELF']; + (array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] == 'on') + ? 'https://' . $this->host . $_SERVER['PHP_SELF'] + : 'http://' . $this->host . $_SERVER['PHP_SELF']; - # + // $dispatch_keys = array_keys($this->soap_server->dispatch_objects); $dc = count($dispatch_keys); - for ($di=0; $di < $dc; $di++) { + 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]; - # types definitions + // types definitions $this->addSchemaFromMap($object->__typedef); - # MESSAGES - $this->addMethodsFromMap($object->__dispatch_map,$namespace,get_class($object)); + // MESSAGES + $this->addMethodsFromMap($object->__dispatch_map, $namespace, get_class($object)); } } - if (isset($server->dispatch_map)) - $this->addMethodsFromMap($server->dispatch_map,$namespace); - + if (isset($server->dispatch_map)) { + $this->addMethodsFromMap($server->dispatch_map, $namespace); + } - # generate wsdl - $this->_generate_WSDL_XML($this->_wsdl); + // generate wsdl + $this->_generate_WSDL_XML(); } - function &_getSchema($namespace) { - # SCHEMA + function &_getSchema($namespace) + { + // SCHEMA $c = count($this->_wsdl['definitions']['types']['schema']); for($i = 0; $i < $c; $i++) { - if ($this->_wsdl['definitions']['types']['schema'][$i]['attr']['targetNamespace'] == $namespace) + if ($this->_wsdl['definitions']['types']['schema'][$i]['attr']['targetNamespace'] == $namespace) { return $this->_wsdl['definitions']['types']['schema'][$i]; + } } - # don't have this namespace + + // don't have this namespace $schema = array(); $schema['attr'] = array(); $schema['complexType'] = array(); $schema['attr']['xmlns'] = array_search('xsd',$this->namespaces); $schema['attr']['targetNamespace'] = $namespace; $this->_wsdl['definitions']['types']['schema'][] =& $schema; + return $schema; } - function addSchemaFromMap(&$map) { - if (!$map) return; + function addSchemaFromMap(&$map) + { + if (!$map) { + return; + } + foreach ($map as $_type_name => $_type_def) { list($typens,$type) = $this->_getTypeNs($_type_name); if ($typens == 'xsd') { // cannot add to xsd, lets use method_namespace $typens = 'tns'; } - $schema =& $this->_getSchema(array_search($typens,$this->namespaces)); + $schema =& $this->_getSchema(array_search($typens, $this->namespaces)); if (!$this->_ifComplexTypeExists($schema['complexType'], $type)) { $ctype =& $schema['complexType'][]; $ctype['attr']['name'] = $type; @@ -194,7 +206,7 @@ $ctype['complexContent']['attr'] = ''; $ctype['complexContent']['restriction']['attr']['base'] = 'SOAP-ENC:Array'; foreach ($_vartype as $array_var => $array_type) { - list($_vartypens,$_vartype) = $this->_getTypeNs($array_type); + list($_vartypens, $_vartype) = $this->_getTypeNs($array_type); $ctype['complexContent']['restriction']['attribute']['attr']['ref'] = 'SOAP-ENC:arrayType'; $ctype['complexContent']['restriction']['attribute']['attr']['wsdl:arrayType'] = $_vartypens . ':' . $_vartype . '[]'; } @@ -211,61 +223,60 @@ } foreach ($map as $method_name => $method_types) { - if (array_key_exists('namespace',$method_types)) { + if (array_key_exists('namespace', $method_types)) { $method_namespace = $method_types['namespace']; } else { $method_namespace = $namespace; } - # INPUT + // INPUT if (isset($method_types['in']) && is_array($method_types['in'])) { $input_message =& $this->_wsdl['definitions']['message'][]; $input_message['attr']['name'] = $method_name . 'Request'; foreach ($method_types['in'] as $name => $type) { - list($typens,$type) = $this->_getTypeNs($type); + list($typens, $type) = $this->_getTypeNs($type); $part =& $input_message['part'][]; $part['attr']['name'] = $name; $part['attr']['type'] = $typens . ':' . $type; } } - # OUTPUT + // OUTPUT if (isset($method_types['out']) && is_array($method_types['out'])) { $output_message =& $this->_wsdl['definitions']['message'][]; $output_message['attr']['name'] = $method_name . 'Response'; foreach ($method_types['out'] as $name => $type) { - list($typens,$type) = $this->_getTypeNs($type); + list($typens, $type) = $this->_getTypeNs($type); $part =& $output_message['part'][]; $part['attr']['name'] = $name; $part['attr']['type'] = $typens . ':' . $type; } } - # PORTTYPES + // PORTTYPES $operation =& $this->_wsdl['definitions']['portType']['operation'][]; - $operation['attr']['name'] = $method_name; - # INPUT + // INPUT $operation['input']['attr']['message'] = 'tns:' . $input_message['attr']['name']; - # OUTPUT + // OUTPUT $operation['output']['attr']['message'] = 'tns:' . $output_message['attr']['name']; - # BINDING + // BINDING $binding =& $this->_wsdl['definitions']['binding']['operation'][]; $binding['attr']['name'] = $method_name; - $action = $method_namespace . '#' . ($classname?$classname . '#':'') . $method_name; + $action = $method_namespace . '#' . ($classname ? $classname . '#' : '') . $method_name; $binding['soap:operation']['attr']['soapAction'] = $action; - # INPUT + // INPUT $binding['input']['attr'] = ''; $binding['input']['soap:body']['attr']['use'] = 'encoded'; $binding['input']['soap:body']['attr']['namespace'] = $method_namespace; $binding['input']['soap:body']['attr']['encodingStyle'] = SOAP_SCHEMA_ENCODING; - # OUTPUT + // OUTPUT $binding['output']['attr'] = ''; $binding['output']['soap:body']['attr']['use'] = 'encoded'; $binding['output']['soap:body']['attr']['namespace'] = $method_namespace; @@ -273,7 +284,8 @@ } } - function _generate_DISCO_XML($disco_array) { + function _generate_DISCO_XML($disco_array) + { $disco = '<?xml version="1.0"?>'; foreach ($disco_array as $key => $val) { $disco .= $this->_arrayToNode($key,$val); @@ -281,18 +293,20 @@ $this->disco = $disco; } - function _generate_WSDL_XML($wsdl_array) { + function _generate_WSDL_XML() + { $wsdl = '<?xml version="1.0"?>'; - foreach ($wsdl_array as $key => $val) { - $wsdl .= $this->_arrayToNode($key,$val); + foreach ($this->_wsdl as $key => $val) { + $wsdl .= $this->_arrayToNode($key, $val); } $this->wsdl = $wsdl; } - function _arrayToNode($node_name = '', $array) { + function _arrayToNode($node_name = '', $array) + { $return = ''; if (is_array($array)) { - # we have a node if there's key 'attr' + // we have a node if there's key 'attr' if (array_key_exists('attr',$array)) { $return .= "<$node_name"; if (is_array($array['attr'])) { @@ -301,7 +315,7 @@ } } - # unset 'attr' and proceed other childs... + // unset 'attr' and proceed other childs... unset($array['attr']); if (count($array) > 0) { @@ -316,26 +330,28 @@ $return .= " />\n"; } } else { - # we have no 'attr' key in array - so it's list of nodes with the same name ... + // we have no 'attr' key in array - so it's list of nodes with + // the same name ... foreach ($array as $child_node_name => $child_node_value) { $return .= $this->_arrayToNode($node_name,$child_node_value); } } } else { - # $array is not an array + // $array is not an array if ($array !='') { - # and its not empty + // and its not empty $return .= "<$node_name>$array</$node_name>\n"; } else { - # and its empty... + // and its empty... $return .= "<$node_name />\n"; } } return $return; } - function _getTypeNs($type) { - preg_match_all("'\{(.*)\}'sm",$type,$m); + function _getTypeNs($type) + { + preg_match_all("'\{(.*)\}'sm", $type, $m); if (isset($m[1][0]) && $m[1][0] != '') { if (!array_key_exists($m[1][0],$this->namespaces)) { $ns_pref = 'ns' . count($this->namespaces); @@ -350,7 +366,8 @@ return array($typens,$type); } - function _ifComplexTypeExists($typesArray, $type_name) { + function _ifComplexTypeExists($typesArray, $type_name) + { if (is_array($typesArray)) { foreach ($typesArray as $index => $type_data) { if ($typesArray[$index]['attr']['name'] == $type_name) { @@ -361,4 +378,3 @@ return false; } } -?> \ No newline at end of file http://cvs.php.net/diff.php/pear/SOAP/package.xml?r1=1.58&r2=1.59&ty=u Index: pear/SOAP/package.xml diff -u pear/SOAP/package.xml:1.58 pear/SOAP/package.xml:1.59 --- pear/SOAP/package.xml:1.58 Thu May 26 16:54:14 2005 +++ pear/SOAP/package.xml Thu May 26 18:26:17 2005 @@ -82,6 +82,8 @@ - Fix PEAR bug #953 - stop code flow and return SOAP fault on errors in userland code. + + - Fix PEAR bug #1657 - create WSDL element in the correct order. </notes> <filelist> <dir name="/" baseinstalldir="SOAP">
« previous php.pear.cvs (#32146) next »