On Thu, Feb 28, 2008 at 5:31 PM, alvaro <[EMAIL PROTECTED]> wrote:
> 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.

That's an interesting option.  Let me think about it a bit.  It's an
API change, but anyone using the backend would have their own copy of
the backend anyway.  (In fact, I could keep it backward-compatible by
continuing to pass $error to the methods but also catch the exception.

I've put this on my list of "things to do".  Thanks for the suggestion!

Derrell

-------------------------------------------------------------------------
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