0xFFFF) throw new InvalidArgumentException('$port is not a valid port number.'); $this->host = $host; $this->port = $port; } public function getHost(): string { return $this->host; } public function hasPort(): bool { return $this->port > 0; } public function getPort(): int { return $this->port; } public function __serialize(): array { return [$this->host, $this->port]; } public function __unserialize(array $serialized): void { $this->host = $serialized[0]; $this->port = $serialized[1]; } public function equals(mixed $other): bool { return $other instanceof DnsEndPoint && $this->port === $other->port && $this->host === $other->host; } public static function parse(string $string): EndPoint { $parts = explode(':', $string); if(count($parts) < 2) throw new InvalidArgumentException('$string is not a valid host and port combo.'); return new DnsEndPoint($parts[0], (int)$parts[1]); } public function __toString(): string { if($this->port < 1) return $this->host; return $this->host . ':' . $this->port; } }