aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/mmccook/php-json-canonicalization-scheme/src
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-03-14 10:18:51 +0000
committerMario <mario@mariovavti.com>2024-03-14 10:18:51 +0000
commit81ce67df942d4bf378814677268fe03a29ecc028 (patch)
tree70cb1eccd45e580aec9bd685d8bdbaaf81ae6ce9 /vendor/mmccook/php-json-canonicalization-scheme/src
parent55097c47c5534d4453f7494f8a1542f7beb4d588 (diff)
downloadvolse-hubzilla-81ce67df942d4bf378814677268fe03a29ecc028.tar.gz
volse-hubzilla-81ce67df942d4bf378814677268fe03a29ecc028.tar.bz2
volse-hubzilla-81ce67df942d4bf378814677268fe03a29ecc028.zip
use the streams php-jcs library until the floats issue will be fixed upstream. see here for reference https://codeberg.org/streams/streams/issues/151
Diffstat (limited to 'vendor/mmccook/php-json-canonicalization-scheme/src')
-rw-r--r--vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizator.php79
-rw-r--r--vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizatorFactory.php13
-rw-r--r--vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizatorInterface.php10
-rw-r--r--vendor/mmccook/php-json-canonicalization-scheme/src/Utils.php52
4 files changed, 0 insertions, 154 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 '}';
-
- }
-}
diff --git a/vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizatorFactory.php b/vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizatorFactory.php
deleted file mode 100644
index 68b1c50c9..000000000
--- a/vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizatorFactory.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Mmccook\JsonCanonicalizator;
-
-class JsonCanonicalizatorFactory
-{
- public static function getInstance(): JsonCanonicalizator
- {
- return new JsonCanonicalizator();
- }
-}
diff --git a/vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizatorInterface.php b/vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizatorInterface.php
deleted file mode 100644
index 73b25c086..000000000
--- a/vendor/mmccook/php-json-canonicalization-scheme/src/JsonCanonicalizatorInterface.php
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Mmccook\JsonCanonicalizator;
-
-interface JsonCanonicalizatorInterface
-{
- public function canonicalize($data, bool $asHex): string;
-}
diff --git a/vendor/mmccook/php-json-canonicalization-scheme/src/Utils.php b/vendor/mmccook/php-json-canonicalization-scheme/src/Utils.php
deleted file mode 100644
index 57079df3b..000000000
--- a/vendor/mmccook/php-json-canonicalization-scheme/src/Utils.php
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-
-namespace Mmccook\JsonCanonicalizator;
-
-class Utils
-{
- /**
- * @param array $array
- * @return bool
- */
- public static function isAssoc(array $array): bool
- {
- $keys = array_keys($array);
-
- return array_keys($keys) !== $keys;
- }
-
- public static function asHex(string $data): string
- {
- return rtrim(chunk_split(bin2hex($data), 2, ' '));
- }
-
- public static function es6NumberFormat(float $number): string
- {
-
- if (is_nan($number) || is_infinite($number)) {
- throw new \RuntimeException("can't use Nan or Infinity in json");
- }
-
- if (0.0 === $number) {
- return '0';
- }
-
- $sign = '';
- if ($number < 0) {
- $sign = '-';
- $number = -$number;
- }
-
- if ($number < 1e+21 && $number >= 1e-6) {
- $formatted = number_format($number, 7, '.', '');
- $formatted = rtrim($formatted, '.0');
- } else {
- $formatted = sprintf('%e', $number);
- $parts = explode('e', $formatted);
- $parts[0] = rtrim($parts[0], '.0');
- $formatted = implode('e', $parts);
- }
-
- return $sign . $formatted;
- }
-}