65535)) { throw new \Error('Port number must be null or an integer between 1 and 65535'); } if (\strrpos($host, ':')) { $host = \trim($host, '[]'); } $this->host = $host; $this->port = $port; } /** * @return string */ public function getHost() : string { return $this->host; } /** * @return int */ public function getPort() : ?int { return $this->port; } /** * @return string host:port formatted string. */ public function toString() : string { $host = $this->host; if (\strrpos($host, ':')) { $host = '[' . $host . ']'; } if ($this->port === null) { return $host; } return $host . ':' . $this->port; } /** * @see toString * * @return string */ public function __toString() : string { return $this->toString(); } }