PHP 8.2.31
Preview: Json.php Size: 2.50 KB
/opt/cpanel/ea-wappspector/vendor/rector/rector/vendor/nette/utils/src/Utils/Json.php

<?php

/**
 * This file is part of the Nette Framework (https://nette.org)
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
 */
declare (strict_types=1);
namespace RectorPrefix202411\Nette\Utils;

use RectorPrefix202411\Nette;
/**
 * JSON encoder and decoder.
 */
final class Json
{
    use Nette\StaticClass;
    /** @deprecated use Json::decode(..., forceArrays: true) */
    public const FORCE_ARRAY = \JSON_OBJECT_AS_ARRAY;
    /** @deprecated use Json::encode(..., pretty: true) */
    public const PRETTY = \JSON_PRETTY_PRINT;
    /** @deprecated use Json::encode(..., asciiSafe: true) */
    public const ESCAPE_UNICODE = 1 << 19;
    /**
     * Converts value to JSON format. Use $pretty for easier reading and clarity, $asciiSafe for ASCII output
     * and $htmlSafe for HTML escaping, $forceObjects enforces the encoding of non-associateve arrays as objects.
     * @throws JsonException
     * @param bool|int $pretty
     * @param mixed $value
     */
    public static function encode($value, $pretty = \false, bool $asciiSafe = \false, bool $htmlSafe = \false, bool $forceObjects = \false) : string
    {
        if (\is_int($pretty)) {
            // back compatibility
            $flags = ($pretty & self::ESCAPE_UNICODE ? 0 : \JSON_UNESCAPED_UNICODE) | $pretty & ~self::ESCAPE_UNICODE;
        } else {
            $flags = ($asciiSafe ? 0 : \JSON_UNESCAPED_UNICODE) | ($pretty ? \JSON_PRETTY_PRINT : 0) | ($forceObjects ? \JSON_FORCE_OBJECT : 0) | ($htmlSafe ? \JSON_HEX_AMP | \JSON_HEX_APOS | \JSON_HEX_QUOT | \JSON_HEX_TAG : 0);
        }
        $flags |= \JSON_UNESCAPED_SLASHES | (\defined('JSON_PRESERVE_ZERO_FRACTION') ? \JSON_PRESERVE_ZERO_FRACTION : 0);
        // since PHP 5.6.6 & PECL JSON-C 1.3.7
        $json = \json_encode($value, $flags);
        if ($error = \json_last_error()) {
            throw new JsonException(\json_last_error_msg(), $error);
        }
        return $json;
    }
    /**
     * Parses JSON to PHP value. The $forceArrays enforces the decoding of objects as arrays.
     * @throws JsonException
     * @param bool|int $forceArrays
     * @return mixed
     */
    public static function decode(string $json, $forceArrays = \false)
    {
        $flags = \is_int($forceArrays) ? $forceArrays : ($forceArrays ? \JSON_OBJECT_AS_ARRAY : 0);
        $flags |= \JSON_BIGINT_AS_STRING;
        $value = \json_decode($json, null, 512, $flags);
        if ($error = \json_last_error()) {
            throw new JsonException(\json_last_error_msg(), $error);
        }
        return $value;
    }
}

Directory Contents

Dirs: 0 × Files: 25

Name Size Perms Modified Actions
2.18 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
3.08 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
16.38 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
4.18 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
3.26 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
784 B lrw-r--r-- 2024-11-08 13:59:10
Edit Download
1.44 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
10.30 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
16.15 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
2.36 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
3.33 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
21.89 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
27.78 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
2.03 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
415 B lrw-r--r-- 2024-11-08 13:59:10
Edit Download
7.05 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
2.50 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
7.90 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
4.98 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
1.38 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
10.49 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
968 B lrw-r--r-- 2024-11-08 13:59:10
Edit Download
25.85 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
7.46 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
12.23 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).