1: | <?php |
2: | namespace Worldline\Acquiring\Sdk\JSON; |
3: | |
4: | use stdClass; |
5: | use UnexpectedValueException; |
6: | |
7: | /** |
8: | * Class JSONUtil |
9: | * |
10: | * @package Worldline\Acquiring\Sdk |
11: | */ |
12: | class JSONUtil |
13: | { |
14: | private function __construct() |
15: | { |
16: | } |
17: | |
18: | /** |
19: | * @param string $value |
20: | * @return stdClass |
21: | * @throws UnexpectedValueException |
22: | */ |
23: | public static function decode($value) |
24: | { |
25: | $object = json_decode($value); |
26: | if (json_last_error()) { |
27: | throw new UnexpectedValueException('Invalid JSON value: ' . json_last_error_msg()); |
28: | } |
29: | return $object; |
30: | } |
31: | } |
32: |