Ensures a connected connection adapter for a host.
Returns the connection adapter instance.

@param Host $host

@return ConnectionAdapterInterface

@throws ConnectionException
540852
public function ensureConnection(Host $host)
    {
        if ($host->hasConnection()) {
            $connection = $host->getConnection();
            if ($connection->isConnected() === false && $connection->connect() === false) {
                throw new ConnectionException(sprintf('Could not connect to "%s" through "%s".', $host->getHostname(), $host->getConnectionType()));
            }

            return $connection;
        }

        throw new ConnectionException(sprintf('No connection adapter of type "%s" found on host.', $host->getConnectionType()));
    }
972165
public function setHostFull(string $host) : self
    {
        $uri = new static($host);

        $this->uri['host'] = $uri->uri['host'];

        if (isset($uri->uri['scheme'])) {
            $this->uri['scheme'] = $uri->uri['scheme'];
        }

        if (isset($uri->uri['port'])) {
            $this->uri['port'] = $uri->uri['port'];
        }

        if (isset($uri->uri['user'])) {
            $this->uri['user'] = $uri->uri['user'];
        }

        if (isset($uri->uri['pass'])) {
            $this->uri['pass'] = $uri->uri['pass'];
        }

        return $this;
    }
1234019
public static function parse(string $host): HostInterface
    {
        if (!self::myParse($host, $hostname, $ipAddress, $error)) {
            throw new HostInvalidArgumentException($error);
        }

        return new self($hostname, $ipAddress);
    }
1035310
public static function tryParse(string $host): ?HostInterface
    {
        if (!self::myParse($host, $hostname, $ipAddress)) {
            return null;
        }

        return new self($hostname, $ipAddress);
    }
1353473
public function connect($host, $ssl = false, $port = 21, $timeout = 90)
    {
        if ($ssl) {
            $this->conn = @$this->ftp->ssl_connect($host, $port, $timeout);
        } else {
            $this->conn = @$this->ftp->connect($host, $port, $timeout);
        }
        if (!$this->conn) {
            throw new FtpException('Unable to connect');
        }

        return $this;
    }
1172244
public function withHost(HostInterface $host): UrlInterface
    {
        return new self($this->myScheme, $host, $this->myPort, $this->myPath, $this->myQueryString, $this->myFragment);
    }
1352636
public function getConnection(string $connectionName)
  {
    $connection = $this->findConnection($connectionName);

    if (is_null($connection)) {
      $connection = $this->createConnection($connectionName);

      if (!is_null($connection)) {
        $this->addConnection($connection);
      }
    }

    return $connection;
  }
1027451
public static function create($host, $port)
  {
    $transceiver = new SocketTransceiver();
    $transceiver->createSocket($host, $port);
    
    return $transceiver;
  }
1060670
protected function createConnection($host, $port, $methods, $callbacks)
    {
        return @ssh2_connect($host, $port, $methods, $callbacks);
    }
378889
public function host($host = '') {
        if ($host) {
            $this->host = $host;
        }
        if (!$this->host) {
            $this->host = self::server('HTTP_HOST');
        }
        return $this->host;
    }
536907
protected static function filterHost($host)
    {
        if (! is_string($host)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid host; must be a string argument; received %s',
                (is_object($host) ? get_class($host) : gettype($host))
            ));
        }

        return $host;
    }
687638
protected function filterHost($host)
    {
        if ($host) {
            if (filter_var($host, FILTER_VALIDATE_IP)) {
                $host = strval($host);
            } elseif (preg_match(
                '/^(?:[' . self::CHARACTERS_UNRESERVED . self::CHARACTERS_SUB_DELIMS . ':@\/\?]+|%[A-Fa-f0-9]{2})+$/',
                $host
            )
            ) {
                $host = strval($host);
            } else {
                throw new InvalidArgumentException('Invalid host "%s".', $host);
            }
        } else {
            $host = '';
        }

        return $host;
    }
811915
public function getUrlForHost($host)
    {
        $newUrl = clone $this;
        $newUrl->_fragments['host'] = $host;
        $newUrl->_inputString = $newUrl->__toString();

        return $newUrl;
    }
235186
public function addHost(Host $host)
    {
        if (empty($host)) return $this;

        $this->_host_list["{$host->name}:{$host->port}"] = $host;

        return $this;
    }
815735
public function setHost($host)
    {
        $this->host = $host;
        if (strpos($host, '/') !== false || strpos($host, '?') !== false) {
            if (strpos($host, 'http') === false) {
                $host = 'https://' . $host;
            }
            $url = parse_url($host);
            $this->host = $url['host'];

            if (isset($url['path'])) {
                $this->setPath($url['path']);
            }

            if (isset($url['query'])) {
                if (!isset($url['path'])) { // for example.org?query=string
                    $this->setPath('/');
                }
                $this->setQuery($url['query']);
            }
        }

        return $this;
    }
851909
public function assertHostIsNot($host)
    {
        $actual = parse_url($this->driver->getCurrentURL(), PHP_URL_HOST) ?? '';

        PHPUnit::assertNotEquals(
            $host, $actual,
            "Host [{$host}] should not equal the actual value."
        );

        return $this;
    }
185927
function _filterHost($host)
    {
        if (strstr($host, ':') !== false)
            throw new \InvalidArgumentException('Host name can`t contains port number.');

        $host = strtolower($host);
        return $host;
    }