/** * Filter the service desrciption (which is derived * from the annotations in the service class) to produce * a "Simple Method Description" object for use by * JSON-RPC (well the DOJO flavour of it anyhow) */ public static function generateSmd($service_desc) { // an array of types used to ensure that complex // type descriptions are only written out once // this is separate from the smd object that is // being built up so that it doesn't get written // out to JSON at the end $type_array = array(); // construct an XMLDAS base on the XSDs in the // service description // // TODO - this xmldas could be provided as part of the // service description. I would like to see a class // hierarchy in PHP that holds the service // description and can be cached if necessary self::$xmldas = SCA_Helper::getXmldasFormXsdArray($service_desc->class_name, $service_desc->xsd_types); // work out what the hostname is so that the // url can be constructed $http_host = null; if (isset($_SERVER['HTTP_HOST'])) { $http_host = $_SERVER['HTTP_HOST']; } else { $http_host = "localhost"; } $smd = new stdClass(); $smd->SMDVersion = ".1"; $smd->serviceType = "JSON-RPC"; $smd->serviceURL = str_replace(' ', '%20', "http://" . $http_host . $_SERVER['SCRIPT_NAME']); $smd->methods = array(); foreach ($service_desc->operations as $operation_name => $operation) { $method = new stdClass(); $method->name = $operation_name; $method->parameters = array(); $smd->methods[] = $method; if (array_key_exists("parameters", $operation) && $operation["parameters"]) { // create the method parameters entries foreach ($operation["parameters"] as $parameter) { $param = new stdClass(); $param->name = $parameter["name"]; if (array_key_exists('objectType', $parameter)) { $param->type = $parameter["objectType"]; self::generateSmdType($smd, $parameter["objectType"], $parameter["namespace"], $type_array); // add the type info to the smd } else { $param->type = $parameter["type"]; } $method->parameters[] = $param; } } if (array_key_exists("return", $operation) && $operation["return"]) { // create the method return type entries foreach ($operation["return"] as $return) { $rtn = new stdClass(); if (array_key_exists('objectType', $return)) { $rtn->type = $return["objectType"]; self::generateSmdType($smd, $return["objectType"], $return["namespace"], $type_array); // add the type info to the smd } else { $rtn->type = $return["type"]; } $method->return = $rtn; } } } // turn the smd into JSON format $str = json_encode($smd); // TODO - hack to remove the encoded /s from the encoded string $str = str_replace("\\/", "/", $str); return $str; }