In the current PHP backend for JSON-RPC methods get an extra argument 
for returning an error in case of problems. See the sample "test" class 
method "echo":

function method_echo($params, $error)
{
   if (count($params) != 1)
   {
     $error->SetError(JsonRpcError_ParameterMismatch,
                      "Expected 1 parameter; got " . count($params));
     return $error;
   }
   return "Client said: [" . $params[0] . "]";
}

Methods would be more intuitive with just the expected $params argument, 
and signaling errors by throwing an exception. This can be done in PHP 
5. The method would be like this (I implemented it and works):

function method_echo($params)
{
   if (count($params) != 1)
     throw new Exception("Expected 1 parameter; got " . count($params),
                         JsonRpcError_ParameterMismatch);

   return "Client said: [" . $params[0] . "]";
}

For it to work it needs a little change in the RPC backend script 
"index.php" in order to include try/catch blocks (at the end, when the 
method is actually called and checked for errors:

try {
   $output = $service->$method($jsonInput->params);
}
catch(Exception $e)
{
   $error->SetError($e->getCode(), $e->getMessage());
   $error->SendAndExit();
}


I think this makes things simpler and more intuitive.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to