PluginProbe ʕ •ᴥ•ʔ
FAPI Member / 2.2.31
FAPI Member v2.2.31
2.2.33 2.2.32 trunk 1.9.47 2.1.18 2.2.24 2.2.25 2.2.26 2.2.28 2.2.29 2.2.30 2.2.31
fapi-member / libs / nette / utils / src / Utils / Json.php
fapi-member / libs / nette / utils / src / Utils Last commit date
ArrayHash.php 1 month ago ArrayList.php 1 month ago Arrays.php 1 month ago Callback.php 1 month ago DateTime.php 1 month ago FileSystem.php 1 month ago Floats.php 1 month ago Helpers.php 1 month ago Html.php 1 month ago Image.php 1 month ago Json.php 1 month ago ObjectHelpers.php 1 month ago ObjectMixin.php 1 month ago Paginator.php 1 month ago Random.php 1 month ago Reflection.php 1 month ago Strings.php 1 month ago Type.php 1 month ago Validators.php 1 month ago exceptions.php 1 month ago
Json.php
50 lines
1 <?php
2
3 /**
4 * This file is part of the Nette Framework (https://nette.org)
5 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6 */
7 declare (strict_types=1);
8 namespace FapiMember\Library\Nette\Utils;
9
10 use FapiMember\Library\Nette;
11 /**
12 * JSON encoder and decoder.
13 */
14 final class Json
15 {
16 use Nette\StaticClass;
17 public const FORCE_ARRAY = \JSON_OBJECT_AS_ARRAY;
18 public const PRETTY = \JSON_PRETTY_PRINT;
19 public const ESCAPE_UNICODE = 1 << 19;
20 /**
21 * Converts value to JSON format. The flag can be Json::PRETTY, which formats JSON for easier reading and clarity,
22 * and Json::ESCAPE_UNICODE for ASCII output.
23 * @param mixed $value
24 * @throws JsonException
25 */
26 public static function encode($value, int $flags = 0): string
27 {
28 $flags = (($flags & self::ESCAPE_UNICODE) ? 0 : \JSON_UNESCAPED_UNICODE) | \JSON_UNESCAPED_SLASHES | $flags & ~self::ESCAPE_UNICODE | (defined('JSON_PRESERVE_ZERO_FRACTION') ? \JSON_PRESERVE_ZERO_FRACTION : 0);
29 // since PHP 5.6.6 & PECL JSON-C 1.3.7
30 $json = json_encode($value, $flags);
31 if ($error = json_last_error()) {
32 throw new JsonException(json_last_error_msg(), $error);
33 }
34 return $json;
35 }
36 /**
37 * Parses JSON to PHP value. The flag can be Json::FORCE_ARRAY, which forces an array instead of an object as the return value.
38 * @return mixed
39 * @throws JsonException
40 */
41 public static function decode(string $json, int $flags = 0)
42 {
43 $value = json_decode($json, null, 512, $flags | \JSON_BIGINT_AS_STRING);
44 if ($error = json_last_error()) {
45 throw new JsonException(json_last_error_msg(), $error);
46 }
47 return $value;
48 }
49 }
50