$server */ public static function fromServer(array $server, Settings $settings): self { $username = trim((string)($server['USERNAME'] ?? $server['USER'] ?? '')); if (!preg_match('/^[A-Za-z0-9][A-Za-z0-9._-]{0,31}$/', $username)) { throw new InvalidArgumentException('Invalid DirectAdmin username'); } $host = Settings::normalizeHost((string)($server['HTTP_HOST'] ?? $server['SERVER_NAME'] ?? '')); if ($host === '') { throw new InvalidArgumentException('Missing source host'); } $serverName = $settings->sourceServerName(); if ($serverName === '') { $serverName = $settings->sanitizeServerName(explode('.', $host)[0] ?? ''); } if ($serverName === '') { throw new InvalidArgumentException('Invalid source server name'); } return new self($username, $host, $serverName, strtoupper((string)($server['REQUEST_METHOD'] ?? 'GET'))); } public function username(): string { return $this->username; } public function sourceHost(): string { return $this->sourceHost; } public function serverName(): string { return $this->serverName; } public function method(): string { return $this->method; } }