get('domain_site_configs', 60, function () { return json_encode(self::readDomainConfigurations()); }); $configurations = json_decode((string) $json, true); if (is_array($configurations)) { return $configurations; } } catch (\Throwable $exception) { // Read the database directly when Redis is unavailable. } try { return self::readDomainConfigurations(); } catch (\Throwable $exception) { return []; } } private static function readDomainConfigurations(): array { $keys = []; $configurations = []; for ($i = 1; $i <= 7; $i++) { $keys[] = 'host_' . $i; $keys[] = 'appname_' . $i; $keys[] = 'theme_' . $i; $configurations['host_' . $i] = ''; $configurations['appname_' . $i] = ''; $configurations['theme_' . $i] = 'venix'; } foreach (Configurations::whereIn('name', $keys)->get() as $configuration) { $configurations[$configuration->name] = (string) $configuration->value; } return $configurations; } private static function defaultAppName(): string { try { $name = (new RedisClient())->get('default_app_name', 60, function () { return (string) Configurations::where('name', 'default_app_name')->value('value'); }); return (string) $name; } catch (\Throwable $exception) { try { return (string) Configurations::where('name', 'default_app_name')->value('value'); } catch (\Throwable $dbException) { return ''; } } } private static function normalizeHost($host): string { $host = trim(strtolower((string) $host)); if ($host === '') { return ''; } if (strpos($host, '://') !== false) { $parsedHost = parse_url($host, PHP_URL_HOST); $host = $parsedHost === null ? $host : $parsedHost; } $host = trim($host, " \t\n\r\0\x0B/"); if (strpos($host, ':') !== false && substr_count($host, ':') === 1) { $host = explode(':', $host, 2)[0]; } return $host; } }