Created
July 5, 2020 04:41
-
-
Save whchi/9d32c2e173b4d8efa64ddbb391d5be33 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| if (!function_exists('jsonEncode')) { | |
| function jsonEncode($payload, int $options = 0, int $depth = 512): string | |
| { | |
| $defaultOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE; | |
| $options = 0 !== $options ? $options : $defaultOptions; | |
| $json = \json_encode($payload, $options, $depth); | |
| if (JSON_ERROR_NONE !== \json_last_error()) { | |
| throw new \InvalidArgumentException( | |
| 'json_encode error: ' . \json_last_error_msg() | |
| ); | |
| } | |
| return $json; | |
| } | |
| } | |
| if (!function_exists('jsonDecode')) { | |
| function jsonDecode(string $payload, bool $assoc = false, int $depth = 512, int $options = 0) | |
| { | |
| $data = \json_decode($payload, $assoc, $depth, $options); | |
| if (JSON_ERROR_NONE !== \json_last_error()) { | |
| throw new \InvalidArgumentException( | |
| 'json_decode error: ' . \json_last_error_msg() | |
| ); | |
| } | |
| return $data; | |
| } | |
| } | |
| if (!function_exists('autoSeq')) { | |
| function autoSeq() | |
| { | |
| for ($i = 0; $i < 9999; $i++) { | |
| yield $i; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment