|
Revision 1513, 1.7 kB
(checked in by mikey, 3 months ago)
|
fix several coding style issues
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
stubClassLoader::load('net::stubbles::php::string::stubRecursiveStringEncoder', |
|---|
| 10 |
'net::stubbles::php::string::stubUTF8Encoder' |
|---|
| 11 |
); |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 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 |
|
|---|
| 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 |
?> |
|---|