Skip to content

Commit ab4207e

Browse files
authored
Merge pull request #17 from Kashin-J/patch-1
Update JsonPack.php
2 parents c1aa5b8 + 0b1cc40 commit ab4207e

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

src/Pack/JsonPack.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,39 @@
1717
class JsonPack implements IPack
1818
{
1919
/**
20-
* JSON打包
20+
* pack JSON
2121
*
22-
* @param mixed $data 待打包数据
23-
* @return string
22+
* This adapter uses the json_encode PHP's functions.
23+
* For further details, please refer to the manual.
24+
* Manual : http://php.net/manual/en/function.json-encode.php
25+
*
26+
* @param mixed $data
27+
* @param int $options
28+
* @param int $depth
29+
* @return mixed
2430
*/
25-
public function pack($data)
31+
public function pack($data, $options = JSON_UNESCAPED_UNICODE, $depth = 512)
2632
{
27-
return json_encode($data, JSON_UNESCAPED_UNICODE);
33+
return json_encode($data, $options, $depth);
2834
}
2935

3036
/**
31-
* JSON解包
37+
* unpack JSON
3238
*
33-
* @param string $data 待解包数据
34-
* @return mixed
39+
* This adapter uses the json_decode PHP's functions.
40+
* For further details, please refer to the manual.
41+
* Manual : http://php.net/manual/en/function.json-decode.php
42+
*
43+
* @param string $data
44+
* @param ... $params
3545
* @throws Exception
46+
* @return mixed
3647
*/
37-
public function unPack($data)
48+
public function unPack($data, ...$params)
3849
{
39-
$value = json_decode($data);
40-
if (empty($value)) {
41-
throw new Exception('Json unPack失败');
50+
$value = json_decode($data, ...$params);
51+
if ($value === null && json_last_error() !== 0) {
52+
throw new Exception('Json unPack faild. Error message : ' . json_last_error_msg());
4253
}
4354
return $value;
4455
}

0 commit comments

Comments
 (0)