fixing login issues
Deploy / deploy (push) Successful in 8s

This commit is contained in:
2026-05-06 12:03:41 +02:00
parent 5c223f87de
commit 4565678c5a
4 changed files with 61 additions and 39 deletions
+7 -6
View File
@@ -85,24 +85,25 @@ class Router
private function respond(int $code, mixed $result): void
{
http_response_code($code);
if (is_array($result)) {
$hasObjects = false;
$isList = array_is_list($result);
foreach ($result as $key => $val) {
if (is_object($val) && method_exists($val, 'toArray')) {
$result[$key] = $val->toArray();
$hasObjects = true;
}
}
if ($hasObjects) {
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
return;
}
if (array_is_list($result) && (empty($result) || !isset($result['data']))) {
$result = ['data' => $result];
if ($hasObjects || ($isList && (empty($result) || !isset($result['data'])))) {
if ($isList) {
$result = ['data' => $result];
}
}
} elseif (is_object($result) && method_exists($result, 'toArray')) {
$result = ['data' => $result->toArray()];
}
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
}