filled($v)); } } if (! function_exists('array_trim_strings')) { function array_trim_strings(array $ary): array { return array_filter($ary, function ($v) { if (! is_string($v)) { return $v; } $v = trim($v); return blank($v) ? null : $v; }); } } if (! function_exists('sync_agent_id')) { function sync_agent_id(): int { return cache()->rememberForever('sync_agent_id', fn () => User::where('username', '$$_pacs_sync_$$')->first()->id); } } if (! function_exists('user_per_page')) { function user_per_page(?int $user_id = null): int { $user_id = (int) ($user_id ?? auth()->id()); return settings()->get("user.{$user_id}.pagination.per_page", config('app.pagination.per_page')); } } if (! function_exists('may')) { function may(BackedEnum|iterable|string $perm): bool { if (auth()->user()->isAdmin()) { return true; } return auth()->user()->can($perm); } } if (! function_exists('human_filesize')) { function human_filesize(int $bytes, $dec = 0): string { $size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; $factor = floor((strlen($bytes) - 1) / 3); if ($factor == 0) { $dec = 0; } return sprintf("%.{$dec}f %s", $bytes / (1024 ** $factor), $size[$factor]); } }