school1) return strtolower($parts[0]); } /** * Map subdomain to a school display name using data/tenants.json if present. * tenants.json structure: { "subdomain-key": "School Display Name" } */ public static function schoolFromSubdomain(Storage $storage): ?string { $sub = self::currentSubdomain(); if (!$sub) return null; try { $tenants = $storage->get('tenants', []); if (!empty($tenants[$sub]) && is_string($tenants[$sub])) { return $tenants[$sub]; } } catch (\Throwable $e) { // ignore } // Fallback heuristic: humanize the subdomain (school-one -> School One) $guess = trim($sub); if ($guess === '') return null; $guess = str_replace(['-', '_'], ' ', $guess); return ucwords($guess); } /** * Determine a school candidate for the current request: * - Prefer explicit $provided (POST/GET) * - Then subdomain mapping */ public static function resolveSchool(Storage $storage, ?string $provided = null): ?string { $provided = is_string($provided) ? trim($provided) : ''; if ($provided !== '') return $provided; return self::schoolFromSubdomain($storage); } }