diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-28 12:17:43 +0200 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-28 12:17:43 +0200 |
| commit | 53f65de9d4163c9c095f2b8e87baca648c3645bd (patch) | |
| tree | 37f167f38b25aa50bd7dd1429438c0245a280a28 /server/vendor/guzzlehttp/guzzle/src/functions.php | |
| parent | 60cfe3ebc039df8d6a468a43a59e7fd8c2a16956 (diff) | |
| parent | 804fa322d841d73ee7592885ec500dc94e91b9e6 (diff) | |
Test
Diffstat (limited to 'server/vendor/guzzlehttp/guzzle/src/functions.php')
| -rwxr-xr-x | server/vendor/guzzlehttp/guzzle/src/functions.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/server/vendor/guzzlehttp/guzzle/src/functions.php b/server/vendor/guzzlehttp/guzzle/src/functions.php index 5e93b22..5ab82af 100755 --- a/server/vendor/guzzlehttp/guzzle/src/functions.php +++ b/server/vendor/guzzlehttp/guzzle/src/functions.php @@ -282,3 +282,49 @@ function is_host_in_noproxy($host, array $noProxyArray) return false; } + +/** + * Wrapper for json_decode that throws when an error occurs. + * + * @param string $json JSON data to parse + * @param bool $assoc When true, returned objects will be converted + * into associative arrays. + * @param int $depth User specified recursion depth. + * @param int $options Bitmask of JSON decode options. + * + * @return mixed + * @throws \InvalidArgumentException if the JSON cannot be decoded. + * @link http://www.php.net/manual/en/function.json-decode.php + */ +function json_decode($json, $assoc = false, $depth = 512, $options = 0) +{ + $data = \json_decode($json, $assoc, $depth, $options); + if (JSON_ERROR_NONE !== json_last_error()) { + throw new \InvalidArgumentException( + 'json_decode error: ' . json_last_error_msg()); + } + + return $data; +} + +/** + * Wrapper for JSON encoding that throws when an error occurs. + * + * @param string $value The value being encoded + * @param int $options JSON encode option bitmask + * @param int $depth Set the maximum depth. Must be greater than zero. + * + * @return string + * @throws \InvalidArgumentException if the JSON cannot be encoded. + * @link http://www.php.net/manual/en/function.json-encode.php + */ +function json_encode($value, $options = 0, $depth = 512) +{ + $json = \json_encode($value, $options, $depth); + if (JSON_ERROR_NONE !== json_last_error()) { + throw new \InvalidArgumentException( + 'json_encode error: ' . json_last_error_msg()); + } + + return $json; +} |
