Files
Investidor-V2/app/Services/OpportunityCanonicalValue.php
T
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

26 lines
621 B
PHP

<?php
namespace App\Services;
/** Normalize object key order only. Ordered coordinates and lists retain their meaning. */
class OpportunityCanonicalValue
{
public static function hash(mixed $value): string
{
return hash('sha256', json_encode(self::normalize($value), JSON_THROW_ON_ERROR));
}
private static function normalize(mixed $value): mixed
{
if (! is_array($value)) {
return $value;
}
$result = array_map(self::normalize(...), $value);
if (! array_is_list($result)) {
ksort($result);
}
return $result;
}
}