root/trunk/src/main/php/net/stubbles/service/jsonrpc/stubJsonRpcWriter.php

Revision 1513, 1.7 kB (checked in by mikey, 3 months ago)

fix several coding style issues

Line 
1 <?php
2 /**
3  * Utility class for creates json data.
4  *
5  * @author      Frank Kleine <mikey@stubbles.net>
6  * @package     stubbles
7  * @subpackage  service_jsonrpc
8  */
9 stubClassLoader::load('net::stubbles::php::string::stubRecursiveStringEncoder',
10                       'net::stubbles::php::string::stubUTF8Encoder'
11 );
12 /**
13  * Utility class for creates json data.
14  *
15  * @package     stubbles
16  * @subpackage  service_jsonrpc
17  * @link        http://json-rpc.org/wiki/specification
18  * @static
19  */
20 class stubJsonRpcWriter extends stubBaseObject
21 {
22     /**
23      * encoder instancer
24      *
25      * @var  stubStringEncoder
26      */
27     protected static $encoder;
28
29     /**
30      * static initializing
31      */
32     // @codeCoverageIgnoreStart
33     public static function __static()
34     {
35         self::$encoder = new stubRecursiveStringEncoder(new stubUTF8Encoder());
36     }
37     // @codeCoverageIgnoreEnd
38
39     /**
40      * send a json fault
41      *
42      * @param   string  $reqId    request id
43      * @param   string  $message  fault message
44      * @return  string
45      */
46     public static function writeFault($reqId, $message)
47     {
48         $fault = array('id'     => $reqId,
49                        'result' => null,
50                        'error'  => self::$encoder->encode($message)
51                  );
52         return json_encode($fault);
53     }
54
55     /**
56      * send a json response
57      *
58      * @param   string  $reqId    request id
59      * @param   string  $result
60      * @return  string
61      */
62     public static function writeResponse($reqId, $result)
63     {
64         $response = array('id'     => $reqId,
65                           'result' => self::$encoder->encode($result),
66                           'error'  => null
67                     );
68         return json_encode($response);
69     }
70 }
71 ?>
Note: See TracBrowser for help on using the browser.