diff options
author | Mario <mario@mariovavti.com> | 2024-03-15 17:14:31 +0100 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-03-15 17:14:31 +0100 |
commit | 5af3c3577843a6f65c402c27607edca98233c08e (patch) | |
tree | f5821b68fb676f79d82d8d29d5c5409f08ead858 /vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizator.php | |
parent | dddcddc453bdbd59e1cafcb8ca8aeb2225dfda9d (diff) | |
download | volse-hubzilla-5af3c3577843a6f65c402c27607edca98233c08e.tar.gz volse-hubzilla-5af3c3577843a6f65c402c27607edca98233c08e.tar.bz2 volse-hubzilla-5af3c3577843a6f65c402c27607edca98233c08e.zip |
another attmpt to install streams/php-jcs via composer
Diffstat (limited to 'vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizator.php')
-rw-r--r-- | vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizator.php | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizator.php b/vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizator.php deleted file mode 100644 index 6a3c82959..000000000 --- a/vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizator.php +++ /dev/null @@ -1,79 +0,0 @@ -<?php - -namespace Mmccook\JsonCanonicalizator; - -class JsonCanonicalizator implements JsonCanonicalizatorInterface -{ - public const JSON_FLAGS = \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES; - - /** - * @param $data - * @param bool $asHex - * @return string - */ - public function canonicalize($data, bool $asHex = false): string - { - ob_start(); - - $this->serialize($data); - - $result = ob_get_clean(); - - return $asHex ? Utils::asHex($result) : $result; - } - - private function serialize($item) - { - if (is_float($item)) { - echo Utils::es6NumberFormat($item); - - return; - } - - if (null === $item || is_scalar($item)) { - echo json_encode($item, self::JSON_FLAGS); - - return; - } - - if (is_array($item) && ! Utils::isAssoc($item)) { - echo '['; - $next = false; - foreach ($item as $element) { - if ($next) { - echo ','; - } - $next = true; - $this->serialize($element); - } - echo ']'; - - return; - } - - if (is_object($item)) { - $item = (array)$item; - } - - uksort($item, function (string $a, string $b) { - $a = mb_convert_encoding($a, 'UTF-16BE'); - $b = mb_convert_encoding($b, 'UTF-16BE'); - - return strcmp($a, $b); - }); - - echo '{'; - $next = false; - foreach ($item as $key => $value) { - //var_dump($key, $value); - if ($next) { - echo ','; - } - $next = true; - $outKey = json_encode((string)$key, self::JSON_FLAGS); - echo $outKey, ':', $this->serialize($value); - } - echo '}'; - - } -} |