runningUnitTests() || $throw) { throw $e; } if ($log) { Log::error('Failed attempt', ['error' => $e]); } return null; } } function attempt_if($condition, callable $callback, bool $log = true): mixed { return value($condition) ? attempt($callback, $log) : null; } function attempt_unless($condition, callable $callback, bool $log = true): mixed { return !value($condition) ? attempt($callback, $log) : null; } function gravatar(string $email, int $size = 192): string { return sprintf("https://www.gravatar.com/avatar/%s?s=$size&d=robohash", md5(Str::lower($email))); } function avatar_or_gravatar(?string $avatar, string $email): string { if (!$avatar) { return gravatar($email); } if (Str::startsWith($avatar, ['http://', 'https://'])) { return $avatar; } return user_avatar_url($avatar); } /** * A quick check to determine if a mailer is configured. * This is not bulletproof but should work in most cases. */ function mailer_configured(): bool { return config('mail.default') && !in_array(config('mail.default'), ['log', 'array'], true); } /** @return array */ function collect_sso_providers(): array { if (License::isCommunity()) { return []; } $providers = []; if ( config('services.google.client_id') && config('services.google.client_secret') && config('services.google.hd') ) { $providers[] = 'Google'; } return $providers; } function get_mtime(string|SplFileInfo $file): int { $file = is_string($file) ? new SplFileInfo($file) : $file; // Workaround for #344, where getMTime() fails for certain files with Unicode names on Windows. return attempt(static fn () => $file->getMTime()) ?? time(); }