flat equal check
This commit is contained in:
@@ -41,6 +41,15 @@ class Util
|
||||
*/
|
||||
public static function areValuesEqual(string $type, mixed $v1, mixed $v2, bool $isUnordered = false): bool
|
||||
{
|
||||
$stack = [[$type, $v1, $v2, $isUnordered]];
|
||||
|
||||
while ($stack) {
|
||||
[$type, $v1, $v2, $isUnordered] = array_pop($stack);
|
||||
|
||||
if ($v1 === $v2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($type === AttributeType::JSON_ARRAY) {
|
||||
if (is_array($v1) && is_array($v2)) {
|
||||
if ($isUnordered) {
|
||||
@@ -56,17 +65,13 @@ class Util
|
||||
$otherValue = $v2[$i];
|
||||
|
||||
if (is_object($itemValue) && is_object($otherValue)) {
|
||||
if (!self::areValuesEqual(AttributeType::JSON_OBJECT, $itemValue, $otherValue)) {
|
||||
return false;
|
||||
}
|
||||
$stack[] = [AttributeType::JSON_OBJECT, $itemValue, $otherValue, false];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($itemValue) && is_array($otherValue)) {
|
||||
if (!self::areValuesEqual(AttributeType::JSON_ARRAY, $itemValue, $otherValue)) {
|
||||
return false;
|
||||
}
|
||||
$stack[] = [AttributeType::JSON_ARRAY, $itemValue, $otherValue, false];
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -76,9 +81,13 @@ class Util
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
continue;
|
||||
}
|
||||
} else if ($type === AttributeType::JSON_OBJECT) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($type === AttributeType::JSON_OBJECT) {
|
||||
if (is_object($v1) && is_object($v2)) {
|
||||
if ($v1 != $v2) {
|
||||
return false;
|
||||
@@ -89,17 +98,13 @@ class Util
|
||||
|
||||
foreach (get_object_vars($v1) as $key => $itemValue) {
|
||||
if (is_object($a1[$key]) && is_object($a2[$key])) {
|
||||
if (!self::areValuesEqual(AttributeType::JSON_OBJECT, $a1[$key], $a2[$key])) {
|
||||
return false;
|
||||
}
|
||||
$stack[] = [AttributeType::JSON_OBJECT, $a1[$key], $a2[$key], false];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($a1[$key]) && is_array($a2[$key])) {
|
||||
if (!self::areValuesEqual(AttributeType::JSON_ARRAY, $a1[$key], $a2[$key])) {
|
||||
return false;
|
||||
}
|
||||
$stack[] = [AttributeType::JSON_ARRAY, $a1[$key], $a2[$key], false];
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -109,10 +114,13 @@ class Util
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $v1 === $v2;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user