Skip to content

Commit aebf2d4

Browse files
author
Ethan
committed
json
1 parent c44b64d commit aebf2d4

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/Json.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
*/
1212
class Json
1313
{
14+
protected static $cb = null;
15+
16+
public static function setResultHandle($cb)
17+
{
18+
static::$cb = $cb;
19+
}
20+
21+
1422
/**
1523
* json encode
1624
* @param $data
@@ -42,7 +50,15 @@ public static function render($data)
4250
*/
4351
public static function renderWithTrue($data = null, $code = '0')
4452
{
45-
return static::render(array('status' => true, 'data' => $data, 'code' => (string)$code));
53+
54+
if (static::$cb) {
55+
return static::render(call_user_func_array(static::$cb, array(true, $data, (string)$code)));
56+
57+
} else {
58+
return static::render(array('status' => true, 'data' => $data, 'code' => (string)$code));
59+
}
60+
61+
return static::render($arr);
4662
}
4763

4864
/**
@@ -53,6 +69,10 @@ public static function renderWithTrue($data = null, $code = '0')
5369
*/
5470
public static function renderWithFalse($data = null, $code = '-1')
5571
{
56-
return static::render(array('status' => false, 'data' => $data, 'code' => (string)$code));
72+
if (static::$cb) {
73+
return static::render(call_user_func_array(static::$cb, array(false, $data, (string)$code)));
74+
} else {
75+
return static::render(array('status' => false, 'data' => $data, 'code' => (string)$code));
76+
}
5777
}
58-
}
78+
}

0 commit comments

Comments
 (0)