--- /dev/null
+<?php
+/*
+ * Created on Oct 19, 2008
+ *
+ * The pupose of this file is to manage the wsdl
+ *
+ * To change the template for this generated file go to
+ * Window - Preferences - PHPeclipse - PHP - Code Templates
+ */
+
+/*
+ * Heres how this works.. its simple... When you define an exportable function
+ * you simple create your function (myFunction($whatever)) and then add it to mfapi_wsdlFunctions
+ *
+ * $mfapi_exportedFunctions["myfunctionname"] = "myFunction";
+ * note that "myfunctionname" serves no purpose except as a place holder in the array - i.e. make it unique
+ *
+ * The XSD is created like so: myFunctionResponse myFunction(myFunctionRequest) - simple eh?
+ * Now, myFunctionResponce/Request (all of these things actually) have only one format
+ * class { string: stringpass[] }
+ *
+ * This means data is passed into your function looking like this (the xsd produced makes it unbounded):
+ * $object->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 .='<?xml version="1.0" encoding="UTF-8"?>'."\n";
+ $return .='<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://minifed.sourceforge.net/res/" targetNamespace="http://minifed.sourceforge.net/res/" version="0.1">'."\n";
+ foreach($soapFunctions as $key => $val) {
+
+ // check the function exists first
+ if(function_exists($val)) {
+ // request type for function
+ //$return .='<xsd:element name="'.$val.'Request" targetNamespace="http://minifed.sourceforge.net/res/">'."\n";
+ $return .='<xsd:element xmlns:ns="http://minifed.sourceforge.net/res/" name="'.$val.'Request" type="ns:'.$val.'Request"/>'."\n";
+ $return .='<xsd:complexType name="'.$val.'Request">'."\n";
+ $return .='<xsd:sequence>'."\n";
+ $return .='<xsd:element name="stringpass" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>'."\n";
+ //$return .='<xsd:element name="stringpass" type="xsd:string"/>'."\n";
+ $return .='</xsd:sequence>'."\n";
+ $return .='</xsd:complexType>'."\n";
+ //$return .='</xsd:element>'."\n";
+
+ // response type for function
+ //$return .='<xsd:element name="'.$val.'Responce" targetNamespace="http://minifed.sourceforge.net/res/">'."\n";
+ $return .='<xsd:element xmlns:ns="http://minifed.sourceforge.net/res/" name="'.$val.'Response" type="ns:'.$val.'Response"/>'."\n";
+ $return .='<xsd:complexType name="'.$val.'Response">'."\n";
+ $return .='<xsd:sequence>'."\n";
+ $return .='<xsd:element name="stringpass" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>'."\n";
+ //$return .='<xsd:element name="stringpass" type="xsd:string" />'."\n";
+ $return .='</xsd:sequence>'."\n";
+ $return .='</xsd:complexType>'."\n";
+ //$return .='</xsd:element>'."\n";
+ }
+ }
+ $return .='</xsd:schema>'."\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 .= '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'."\n";
+ $retarray .= '<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://minifed.sourceforge.net/res/" ';
+ $retarray .= 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="minifedAPI" ';
+ $retarray .= 'targetNamespace="http://minifed.sourceforge.net/res/">'."\n";
+
+ $retarray .= "\n";
+
+ // add the xsd link
+ $retarray .= '<wsdl:types>'."\n";
+ //$retarray .= '<xsd:schema targetNamespace="http://minifed.sourceforge.net/res/">'."\n";
+ $retarray .= '<xsd:schema>'."\n";
+ $retarray .= '<xsd:import schemaLocation="'.$location.'?xsd" namespace="http://minifed.sourceforge.net/res/" />'."\n";
+ //$retarray .= mfapi_generateXSD("none");
+ $retarray .= '</xsd:schema>'."\n";
+ $retarray .= '</wsdl:types>'."\n";
+
+ // now the message types
+ foreach($soapFunctions as $key => $val) {
+
+ // check the function exists first
+ if(function_exists($val)) {
+ $retarray .= '<wsdl:message name="'.$val.'Request">'."\n";
+ $retarray .= "\t".'<wsdl:part name="parameters" element="tns:'.$val.'Request"/>'."\n";
+ $retarray .= '</wsdl:message>'."\n";
+ $retarray .= '<wsdl:message name="'.$val.'Response">'."\n";
+ $retarray .= "\t".'<wsdl:part name="parameters" element="tns:'.$val.'Response"/>'."\n";
+ $retarray .= '</wsdl:message>'."\n";
+ }
+
+ }
+
+ $retarray .= "\n";
+
+ // now the port types
+ $retarray .= '<wsdl:portType name="minifedAPIPortType">'."\n";
+ foreach($soapFunctions as $key => $val) {
+ // check the function exists first
+ if(function_exists($val)) {
+ // foreach operation
+ $retarray .= "\t".'<wsdl:operation name="'.$val.'">'."\n";
+ $retarray .= "\t\t".'<wsdl:input message="tns:'.$val.'Request"/>'."\n";
+ $retarray .= "\t\t".'<wsdl:output message="tns:'.$val.'Response"/>'."\n";
+ $retarray .= "\t".'</wsdl:operation>'."\n";
+ }
+ }
+ $retarray .= '</wsdl:portType>'."\n";
+
+ $retarray .= "\n";
+
+ // now the binding
+ $retarray .= '<wsdl:binding name="mfapiSOAP" type="tns:minifedAPIPortType">'."\n";
+ $retarray .= "\t".'<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>'."\n";
+ foreach($soapFunctions as $key => $val) {
+ if(function_exists($val)) {
+ // foreach operation
+ $retarray .= "\t".'<wsdl:operation name="'.$val.'">'."\n";
+ $retarray .= "\t\t".'<soap:operation soapAction="" />'."\n";
+ $retarray .= "\t\t".'<wsdl:input>'."\n";
+ $retarray .= "\t\t\t".'<soap:body use="literal" />'."\n";
+ $retarray .= "\t\t".'</wsdl:input>'."\n";
+ $retarray .= "\t\t".'<wsdl:output>'."\n";
+ $retarray .= "\t\t\t".'<soap:body use="literal" />'."\n";
+ $retarray .= "\t\t".'</wsdl:output>'."\n";
+
+ $retarray .= "\t".'</wsdl:operation>'."\n";
+ }
+ }
+
+ $retarray .= '</wsdl:binding>'."\n";
+
+ $retarray .= "\n";
+
+ // and the end bit
+ $retarray .= '<wsdl:service name="minifedAPI">'."\n";
+ $retarray .= "\t".'<wsdl:port binding="tns:mfapiSOAP" name="mfapiPort">'."\n";
+ $retarray .= "\t\t".'<soap:address location="'.$location.'"/>'."\n";
+ $retarray .= "\t".'</wsdl:port>'."\n";
+ $retarray .= '</wsdl:service>'."\n";
+ $retarray .= '</wsdl:definitions>'."\n";
+
+
+ // and return the array
+ return $retarray;
+}
+
+?>
$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