-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2743d30
commit dfca766
Showing
6 changed files
with
47 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,9 @@ | |
"autoload": { | ||
"psr-4": { | ||
"RingCentral\\": "lib/" | ||
} | ||
}, | ||
"files": [ | ||
"src/core/functions.php" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace RingCentral\core; | ||
|
||
use InvalidArgumentException; | ||
|
||
function json_parse($json, $assoc = false, $depth = 512) | ||
{ | ||
|
||
$parsed = \json_decode($json, $assoc, $depth); | ||
|
||
$error = json_last_error(); | ||
|
||
switch ($error) { | ||
case JSON_ERROR_NONE: | ||
break; | ||
case JSON_ERROR_DEPTH: | ||
throw new InvalidArgumentException('JSON Error: Maximum stack depth exceeded'); | ||
break; | ||
case JSON_ERROR_CTRL_CHAR: | ||
throw new InvalidArgumentException('JSON Error: Unexpected control character found'); | ||
break; | ||
case JSON_ERROR_SYNTAX: | ||
throw new InvalidArgumentException('JSON Error: Syntax error, malformed JSON'); | ||
break; | ||
default: | ||
throw new InvalidArgumentException('JSON Error: Unknown error'); | ||
break; | ||
} | ||
|
||
// This is a courtesy by PHP JSON parser to parse "null" into null, but this is an error situation | ||
if (empty($parsed)) { | ||
throw new InvalidArgumentException('JSON Error: Result is empty after parsing'); | ||
} | ||
|
||
return $parsed; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters