From 7038178201d82ccb9eadad37ee5b95e01d838836 Mon Sep 17 00:00:00 2001 From: paulr Date: Wed, 30 Mar 2011 14:18:53 +1100 Subject: [PATCH] getting soap functional. --- lib/lib.php | 1 + lib/wsdl.php | 196 ++++++++++++++++++++++++++++++++++++++++++++++++ unittests/soaptest.php | 17 ++++ www/soap.php | 37 +++++++-- 4 files changed, 243 insertions(+), 8 deletions(-) create mode 100644 lib/wsdl.php create mode 100644 unittests/soaptest.php diff --git a/lib/lib.php b/lib/lib.php index 1a85a5e..13d5757 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -1,6 +1,7 @@ stringpass[0] = "something"; + * $object->stringpass[1] = "something"; + * + * And you need to pass out the same way, i.e.: + * $mypassout = new dataContainer(); + * $mypassout->stringpass[0] = "something"; + * etc... + * return $mypassout; + * + * I was planning on implementing a way for functions to define "real" schemas and have + * the above as a default, but for now, this will do. Technically its not a "kind" thing + * to do because the only person who knows what the funtions expects and what the function + * returns is the person coding the function. But this will change, and later this will be the + * default, but you'll be expected to define a schema for your function, unless your function + * really is just returning a list of strings. This becomes important later on when + * the web comes into play because in order for the website to be able to accept input for + * foreign data, it'll need to know how to format a form (for example) + * + * I expect this will take the form of something like + * function myFunction(); + * function myFunctionInSchema(); + * function myFunctionOutSchema(); + * or maybe these will take the form of some functional array.. It requires some + * thought, but you'll still just define the one thing in the wsdlFunctions array. + * + * + * $mfapi_exportedFunctions has the following format + * + * $mfapi_exportedFunctions[funcname] = "name"; + * + * format simplified at commit 694 in home repo + */ + + // this the class used to pass around data between soap connections + // Im really not a fan of OO in php... + class dataContainer { + public $stringpass; + }; + +// function for generation of XSD +function sp_generateXSD($location, $soapFunctions) +{ + + + $return = ""; + + $return .=''."\n"; + $return .=''."\n"; + foreach($soapFunctions as $key => $val) { + + // check the function exists first + if(function_exists($val)) { + // request type for function + //$return .=''."\n"; + $return .=''."\n"; + $return .=''."\n"; + $return .=''."\n"; + $return .=''."\n"; + //$return .=''."\n"; + $return .=''."\n"; + $return .=''."\n"; + //$return .=''."\n"; + + // response type for function + //$return .=''."\n"; + $return .=''."\n"; + $return .=''."\n"; + $return .=''."\n"; + $return .=''."\n"; + //$return .=''."\n"; + $return .=''."\n"; + $return .=''."\n"; + //$return .=''."\n"; + } + } + $return .=''."\n"; + + return $return; +} + +// This function was greatly simplified at commit 694. +// I need to generate as xsd as well +function sp_generateWSDL($location, $soapFunctions) +{ + + $retarray = ""; + + // first the header + $retarray .= ''."\n"; + $retarray .= ''."\n"; + //$retarray .= mfapi_generateXSD("none"); + $retarray .= ''."\n"; + $retarray .= ''."\n"; + + // now the message types + foreach($soapFunctions as $key => $val) { + + // check the function exists first + if(function_exists($val)) { + $retarray .= ''."\n"; + $retarray .= "\t".''."\n"; + $retarray .= ''."\n"; + $retarray .= ''."\n"; + $retarray .= "\t".''."\n"; + $retarray .= ''."\n"; + } + + } + + $retarray .= "\n"; + + // now the port types + $retarray .= ''."\n"; + foreach($soapFunctions as $key => $val) { + // check the function exists first + if(function_exists($val)) { + // foreach operation + $retarray .= "\t".''."\n"; + $retarray .= "\t\t".''."\n"; + $retarray .= "\t\t".''."\n"; + $retarray .= "\t".''."\n"; + } + } + $retarray .= ''."\n"; + + $retarray .= "\n"; + + // now the binding + $retarray .= ''."\n"; + $retarray .= "\t".''."\n"; + foreach($soapFunctions as $key => $val) { + if(function_exists($val)) { + // foreach operation + $retarray .= "\t".''."\n"; + $retarray .= "\t\t".''."\n"; + $retarray .= "\t\t".''."\n"; + $retarray .= "\t\t\t".''."\n"; + $retarray .= "\t\t".''."\n"; + $retarray .= "\t\t".''."\n"; + $retarray .= "\t\t\t".''."\n"; + $retarray .= "\t\t".''."\n"; + + $retarray .= "\t".''."\n"; + } + } + + $retarray .= ''."\n"; + + $retarray .= "\n"; + + // and the end bit + $retarray .= ''."\n"; + $retarray .= "\t".''."\n"; + $retarray .= "\t\t".''."\n"; + $retarray .= "\t".''."\n"; + $retarray .= ''."\n"; + $retarray .= ''."\n"; + + + // and return the array + return $retarray; +} + +?> diff --git a/unittests/soaptest.php b/unittests/soaptest.php new file mode 100644 index 0000000..2a0fe56 --- /dev/null +++ b/unittests/soaptest.php @@ -0,0 +1,17 @@ + 1)); + +print_r($client->__getFunctions()); + +$mk = new dataContainer(); +$mk->stringpass[0] = "mix"; +$mk->stringpass[1] = "me"; + +$lk = $client->status($mk); + +print_r($lk); +?> \ No newline at end of file diff --git a/www/soap.php b/www/soap.php index 454c201..281b468 100644 --- a/www/soap.php +++ b/www/soap.php @@ -4,33 +4,54 @@ require_once("../lib/lib.php"); $soapFunctions["status"] = "status"; global $soapFunctions; -function status() +function status($status) { - return "im good"; + $lk = new dataContainer(); + $lk->stringpass[0] = "yes"; + $lk->stringpass[1] = "np"; + return $lk; } if(isset($_REQUEST["wsdl"])) { - generateWSDL(); + $mylocation = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"]; + generateWSDL($mylocation, $soapFunctions); exit(0); } if(isset($_REQUEST["xsd"])) { - //generateXSD(); + $mylocation = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"]; + generateXSD($mylocation, $soapFunctions); exit(0); } -function generageWSDL() +if($_SERVER["REQUEST_METHOD"] != "POST") { + $mylocation = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"]; + generateWSDL($mylocation, $soapFunctions); + exit(0); +} + +function generateWSDL($location, $functions) +{ + header("Content-type: text/xml"); + $wsdl = sp_generateWSDL($location, $functions); + echo $wsdl; +} + +function generateXSD($location, $functions) { - + header("Content-type: text/xml"); + $wsdl = sp_generateXSD($location, $functions); + echo $wsdl; } -$s = new SoapServer(NULL, array( "uri" => "http://pjr.cc/glcas")); +$mylocation = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"]; +$s = new SoapServer("$mylocation?wsdl"); foreach($soapFunctions as $function) { $s->addFunction($function); } -print_r($s->getFunctions()); +$s->handle(); ?> \ No newline at end of file -- 1.7.0.4