summaryrefslogtreecommitdiff
path: root/server/vendor/guzzlehttp/guzzle/src/functions.php
diff options
context:
space:
mode:
authorEoleDev <EoleDev@outlook.fr>2016-03-23 15:30:47 +0100
committerEoleDev <EoleDev@outlook.fr>2016-03-23 15:30:47 +0100
commit54ec6723deb44e325782afd366eeec01ee29ac55 (patch)
tree5431400d307754a02e6c40b35a40e6761d7dac0c /server/vendor/guzzlehttp/guzzle/src/functions.php
parent0dc17aa9efb987dcdf6f864f4110450bcc0c9003 (diff)
Maj Library
Diffstat (limited to 'server/vendor/guzzlehttp/guzzle/src/functions.php')
-rw-r--r--server/vendor/guzzlehttp/guzzle/src/functions.php46
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 100644
--- 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;
+}