$server */ public static function fromServer(array $server, Settings $settings): self { $username = trim((string)($server['USERNAME'] ?? '')); if (!preg_match('/^[A-Za-z0-9][A-Za-z0-9._-]{0,31}$/', $username)) { throw new InvalidArgumentException('Invalid DirectAdmin username'); } $host = self::trustedSourceHost($server); 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'))); } /** * @param array $server */ private static function trustedSourceHost(array $server): string { return Settings::normalizeHost((string)($server['SERVER_NAME'] ?? '')); } public function username(): string { return $this->username; } public function sourceHost(): string { return $this->sourceHost; } public function serverName(): string { return $this->serverName; } public function auditServerName(): string { return $this->sourceHost; } public function method(): string { return $this->method; } }