* @copyright Copyright (c) 2005-2006 Dominique Stender - http://sf.net/projects/cpaint * @version $id: cpaint2.wsdl.php 313 2006-09-30 08:22:39Z saloon12yrd $ */ /** * CPAINT WSDL generation library * * @package CPAINT * @access public * @author Dominique Stender * @copyright Copyright (c) 2005-2006 Dominique Stender - http://sf.net/projects/cpaint * @version 1.0.0 */ class cpaint_wsdl { /** * Classes version * * @access public * @var string $version */ public $version = '1.0.0'; /** * array of API function names and their I/O parameters * * @access protected * @var array $functions */ public $functions; /** * array of complex type schemata * * @access protected * @var array $types */ public $types; /** * base name of the script providing the CPAINT api, with out extension * * @access protected * @var string $basename */ public $basename; /** * full URL to the CPAINT service * * @access protected * @var string $api_url */ public $api_url; /** * targetNamespace * * @access protected * @var string $tns */ public $tns; /** * URI of this service * * @access protected * @var string $uri */ public $uri; /** * constructor * * @access public * @return void */ public function cpaint_wsdl() { // register the destructor register_shutdown_function(array(&$this, '__destruct')); $this->__construct(); } /** * PHP5 constructor * * @access public * @return void */ public function __construct() { $this->functions = array(); $this->types = array(); $this->basename = preg_replace('/\.[a-z0-9]+$/', '', basename($_SERVER['SCRIPT_NAME'])); $this->tns = 'http://' . $_SERVER['SERVER_NAME'] . '/soap/' . $this->basename; $this->uri = $_SERVER['SERVER_NAME'] . '/CPAINT/' . $this->basename . '/'; $this->api_url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']; } /** * destructor * * @access private * @return void */ public function __destruct() { } /** * generates the WSDL for a CPAINT API * * @access public * @param array $functions array of functions and their I/O parameter schemata * @param array $types array of complex type definitions * @return string */ public function generate($functions, $types) { $return_value = ''; $this->functions = (array) $functions; $this->types = (array) $types; // open base node $return_value .= ''; // iterate over all complex types $return_value .= '' . '' . '' . ''; foreach ($this->types as $type_definition) { $return_value .= $this->complex_type($type_definition); } // end: foreach $return_value .= '' . ''; // iterate over all registered functions foreach ($this->functions as $function_name => $function_definition) { // build the request $return_value .= $this->request($function_name); // build the response $return_value .= $this->response($function_name); } // end: foreach // add port and binding information $return_value .= $this->port_information() . $this->binding_information() . $this->service_information(); // close base node $return_value .= ''; return $return_value; } /** * generates a WSDL representation for all complex types * * @access protected * @param array $type_definition schema of the complex type * @return string */ public function complex_type($type_definition) { $return_value = ''; $type_definition = (array) $type_definition; switch ($type_definition['type']) { case 'complex': $return_value .= '' . ''; // recurse through the structure if (is_array($type_definition['struct'])) { foreach ($type_definition['struct'] as $structure) { $return_value .= $this->data_element($structure['name'], $structure['type']); } // end: foreach } // end: if $return_value .= '' . ''; break; case 'list': $return_value .= '' . '' . '' . '' . '' . '' . ''; break; case 'restriction': $return_value .= '' . ''; // iterate over all allowed values if (is_array($type_definition['values'])) { foreach ($type_definition['values'] as $value) { $return_value .= ''; } // end: foreach } // end: if $return_value .= '' . ''; break; default: // unknown type } // end: switch return $return_value; } /** * handles a single element of a complex data type * * @access protected * @param string $element_name name of the element * @param mixed $element_type data type of the element * @return string */ public function data_element($element_name, $element_type) { $return_value = ''; $element_name = (string) $element_name; $element_type = $this->data_type($element_type); if ($element_type != '') { $return_value = ''; } // end: if return $return_value; } /** * creates a XML datatype from a given type * * @access protected * @param string $type native type * @return string */ public function data_type($type) { $return_value = ''; $type = (string) $type; switch (strtolower($type)) { // supported scalar types case 'ENTITIES': case 'ENTITY': case 'ID': case 'IDREF': case 'IDREFS': case 'NCName': case 'NMTOKEN': case 'NMTOKENS': case 'Name': case 'anySimpleType': case 'anyType': case 'base64': case 'base64Binary': case 'boolean': case 'byte': case 'date': case 'dateTime': case 'decimal': case 'double': case 'duration': case 'float': case 'gDay': case 'gMonth': case 'gMonthDay': case 'gYear': case 'gYearMonth': case 'hexBinary': case 'i4': case 'int': case 'integer': case 'language': case 'long': case 'negativeInteger': case 'nonNegativeInteger': case 'nonPositiveInteger': case 'normalizedString': case 'positiveInteger': case 'short': case 'string': case 'time': case 'timeInstant': case 'token': case 'unsignedByte': case 'unsignedInt': case 'unsignedLong': case 'unsignedShort': case 'ur-type': $return_value = 'xsd:' . $type; break; default: foreach ($this->types as $id => $type_definition) { if ($type_definition['name'] == $type) { $return_value = 'tns:' . $type; break; } // end: if } // end: foreach } // end: switch return $return_value; } /** * generates a XML representation of a request / response argument * * @access private * @param string $name name of the argument * @param string $type data type of that argument * @return string */ public function part($name, $type) { $return_value = false; $name = (string) $name; $type = $this->data_type($type); if ($type != '') { $return_value = ''; } // end: if return $return_value; } /** * generates a WSDL representation for a request * * @access protected * @param string $request_name name of the request * @return string */ public function request($request_name) { $return_value = ''; $request_name = (string) $request_name; $return_value .= '' . $this->part('head', 'cpaintRequestHead'); // iterate over all request arguments foreach ($this->functions[$request_name]['input'] as $structure) { $return_value .= $this->part($structure['name'], $structure['type']); } // end: foreach $return_value .= '' . ''; return $return_value; } /** * generates a WSDL representation for a response * * @access protected * @param string $response_name name of the response * @return string */ public function response($response_name) { $return_value = ''; $response_name = (string) $response_name; $return_value .= '' . $this->part('head', 'cpaintResponseHead'); // iterate over all response argument foreach ($this->functions[$response_name]['output'] as $structure) { $return_value .= $this->part($structure['name'], $structure['type']); } // end: foreach $return_value .= ''; return $return_value; } /** * generates the port information * * @access protected * @return string */ public function port_information() { $return_value = ''; // describe all API operations foreach ($this->functions as $function_name => $function_definition) { $return_value .= '' . '' . $function_definition['comment'] . '' . '' . '' . ''; } // end: foreach $return_value .= ''; return $return_value; } /** * generates the binding information * * @access protected * @return string */ public function binding_information() { $return_value = '' . ''; // describe all API operations foreach ($this->functions as $function_name => $function_definition) { $return_value .= '' . '' . '' . '' . '' . '' . '' . '' . ''; } // end: foreach $return_value .= ''; return $return_value; } /** * generates the service information * * @access protected * @return string */ public function service_information() { $return_value = '' . '' . '' . '' . ''; return $return_value; } } ?>