@param Weblink $weblink
@param string  $host    complete base url (scheme+host) eg http://sub.domain.tld
558804
public static function fromWeblinkWithHost(Weblink $weblink, $host)
    {
        $urlParts = parse_url($weblink->getUrl());
        unset($urlParts['host']);
        unset($urlParts['scheme']);

        $urlWithHost = http_build_url($host, $urlParts);

        return new static($urlWithHost, $weblink->getRel(), $weblink->getAttributes());
    }
722632
protected function setCurrentSiteInfo($host, $path)
    {
        $path = $this->formatPath($path);
        $currentSiteId = null;
        $currentLanguage = null;
        $currentAliasId = null;
        $matchingLength = -1;

        $matchingSites = $this->siteRepository->findByAliasDomain($host);

        /** @var ReadSiteInterface $site */
        foreach ($matchingSites as $site) {
            foreach ($site->getAliases() as $aliasId => $alias) {
                $aliasPrefix = $this->formatPath($alias->getPrefix());
                if ($host == $alias->getDomain() && strpos($path, $aliasPrefix) === 0) {
                    $splitLength = count(explode('/', $aliasPrefix));
                    if ($splitLength > $matchingLength) {
                        $currentSiteId = $site->getSiteId();
                        $currentLanguage = $alias->getLanguage();
                        $currentAliasId = $aliasId;
                        $matchingLength = $splitLength;
                    }
                }
            }
        }

        if (is_null($currentSiteId)) {
            throw new NonExistingSiteException();
        }

        $this->currentSiteManager->setSiteId($currentSiteId);
        $this->currentSiteManager->setLanguage($currentLanguage);

        $this->request->attributes->set('siteId', $currentSiteId);
        $this->request->attributes->set('_locale', $currentLanguage);
        $this->request->attributes->set('aliasId', $currentAliasId);
    }
253576
public function deleteResourceLink($resourceLink)
    {

// Delete any outstanding share keys for resource links for this consumer
        $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' ' .
                       'WHERE (resource_link_pk = %d)',
                       $resourceLink->getRecordId());
        $ok = mysql_query($sql);

// Delete users
        if ($ok) {
            $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' .
                           'WHERE (resource_link_pk = %d)',
                           $resourceLink->getRecordId());
            $ok = mysql_query($sql);
        }

// Update any resource links for which this is the primary resource link
        if ($ok) {
            $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' .
                           'SET primary_resource_link_pk = NULL ' .
                           'WHERE (primary_resource_link_pk = %d)',
                           $resourceLink->getRecordId());
            $ok = mysql_query($sql);
        }

// Delete resource link
        if ($ok) {
            $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' .
                           'WHERE (resource_link_pk = %s)',
                           $resourceLink->getRecordId());
            $ok = mysql_query($sql);
        }

        if ($ok) {
            $resourceLink->initialize();
        }

        return $ok;

    }
289234
protected static function getHostAndPortFromHeader(&$host, &$port, $headerHost)
    {
        if (is_array($headerHost)) {
            $headerHost = implode(', ', $headerHost);
        }

        $host = $headerHost;

        if (preg_match('|\:(\d+)$|', $host, $matches)) {
            $host = substr($host, 0, -1 * (strlen($matches[1]) + 1));
            $port = (int) $matches[1];
        }
    }
1105
public function setHost($host)
    {
        if (! (self::_isHostname($host) || self::_isIpAddress($host))) {

            throw new InvalidArgumentException("Invalid host ($host)");
        }

        $this->_host = strtolower(trim($host));
    }
569115
public function setHost($host)
    {
        if (substr($host, -1) === '/') {
            $host = substr($host, 0, strlen($host) - 1);
        }

        $this->host = $host;
    }
43082
private function _parseMemcacheAddress($link)
    {
        $protoSeparator = strpos($link, '://');
        if ($protoSeparator !== false) {
            $link = substr($link, $protoSeparator + 3);
        }
        $server = $link;
        $serverOptions = [];
        $hookSeparator = strpos($link, '?');
        if ($hookSeparator !== false) {
            $server = substr($link, 0, $hookSeparator);
            parse_str(substr($link, $hookSeparator + 1), $serverOptions);
        }
        $server = explode(':', $server);
        $serverOptions['host'] = $server[0];
        $serverOptions['port'] = $server[1];
        return $serverOptions;
    }
1298132
public function addHost($host)
    {
        if (!isset($this->hosts[$host])) {
            $this->hosts[$host] = $host;
        }

        return $this;
    }
824367
public function getLink(string $host = null): ?Link
    {
        // link exists?
        // e.g: getLink('localhost')
        if ($host && isset($this->links[$host])) {
            return $this->links[$host];
        }

        $host = trim((string) $host);
        // with master/slave directives
        if (true === $this->config->get('sharding')) {
            // e.g: getLink(), getLink('master'), getLink('master.mysql.local')
            if ($host == '' || $host == Link::TYPE_MASTER) {
                return Util::arrayRand(
                    array_filter($this->links, function($link) {
                        return $link->getType() == Link::TYPE_MASTER;
                }));
            }
            // e.g: getLink(), getLink('slave'), getLink('slave1.mysql.local')
            elseif ($host == Link::TYPE_SLAVE) {
                return Util::arrayRand(
                    array_filter($this->links, function($link) {
                        return $link->getType() == Link::TYPE_SLAVE;
                }));
            }
        } else {
            // e.g: getLink()
            if ($host == '') {
                return Util::arrayRand(
                    array_filter($this->links, function($link) {
                        return $link->getType() == Link::TYPE_SINGLE;
                }));
            }
        }
    }
212643
public static function isRemoteLink($link)
    {
        $base = Grav::instance()['uri']->rootUrl(true);

        // Sanity check for local URLs with absolute URL's enabled
        if (Utils::startsWith($link, $base)) {
            return false;
        }

        return (0 === strpos($link, 'http://') || 0 === strpos($link, 'https://') || 0 === strpos($link, '//'));
    }
258583
function symlink($target, $link)
    {
        if (!($this->bitmap & SSH2::MASK_LOGIN)) {
            return false;
        }

        //$target = $this->_realpath($target);
        $link = $this->_realpath($link);

        $packet = pack('Na*Na*', strlen($target), $target, strlen($link), $link);
        if (!$this->_send_sftp_packet(NET_SFTP_SYMLINK, $packet)) {
            return false;
        }

        $response = $this->_get_sftp_packet();
        if ($this->packet_type != NET_SFTP_STATUS) {
            user_error('Expected SSH_FXP_STATUS');
            return false;
        }

        if (strlen($response) < 4) {
            return false;
        }
        extract(unpack('Nstatus', $this->_string_shift($response, 4)));
        if ($status != NET_SFTP_STATUS_OK) {
            $this->_logError($response, $status);
            return false;
        }

        return true;
    }
422011
protected function link($link, $anchor = "") {
        $link = trim($link);
        if (preg_match("/^(https?|s?ftp):\/\/.+$/i", $link)) {
            $link = trim($link, ",.?!");
            return array('content' => $link, 'url' => $link);
        } else {
            $callbackargs = $this->linkgeneratorcallbackargs;
            $callbackargs['anchor'] = $anchor;
            $link = call_user_func_array($this->linkgeneratorcallback, array($link, $callbackargs));

            if (isset($link['link_info'])) {
                $l = $link['link_info']['link'];
                unset($link['link_info']['link']);
                $this->returnvalues['link_count'][$l] = $link['link_info'];
            }
            return $link;
        }
    }
154074
protected function assembleHost(Url $host) {
		if (! $host->hasHost()) {
			$host->setHost($this->defaultHost);
		}
		
		if (preg_match('/\.sock$/i', $host->getHost())) {
			$host->removePort();
		} else if (! $host->hasPort()) {
			$host->setPort($this->defaultPort);
		}
		
		return trim($host->assemble(), '/');
	}
1214958
public function setAboutLink($link)
    {
        if (false === filter_var($link, FILTER_VALIDATE_URL)) {
            throw new \InvalidArgumentException(sprintf('Provided link %s is not a valid resource', $link));
        }

        $this->links['about']['href'] = (string) $link;
    }
302953
public void setHost(String host)
        throws java.net.UnknownHostException
    {
        _addr=null;
        if (host!=null)
        {
            if (host.indexOf('/')>0)
                host=host.substring(0,host.indexOf('/'));
            _addrIsHost=!Character.isDigit((host.charAt(0)));
            _addr=InetAddress.getByName(host);
        }
    }
1053279
public function withHost(string $host): URI
    {
        $result = clone $this;
        $result->host = $this->filterHost($host);

        return $result;
    }
385005
public function saveResourceLink($resourceLink) {

        $time = time();
        $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
        $settingsValue = serialize($resourceLink->getSettings());
        if (!empty($resourceLink->getContext())) {
            $consumerId = null;
            $contextId = strval($resourceLink->getContext()->getRecordId());
        } else if (!empty($resourceLink->getContextId())) {
            $consumerId = null;
            $contextId = strval($resourceLink->getContextId());
        } else {
            $consumerId = strval($resourceLink->getConsumer()->getRecordId());
            $contextId = null;
        }
        if (empty($resourceLink->primaryResourceLinkId)) {
            $primaryResourceLinkId = null;
        } else {
            $primaryResourceLinkId = $resourceLink->primaryResourceLinkId;
        }
        $id = $resourceLink->getRecordId();
        if (empty($id)) {
            $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' (consumer_pk, context_pk, ' .
                   'lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated) ' .
                   'VALUES (:cid, :ctx, :rlid, :settings, :prlid, :share_approved, :created, :updated)';
            $query = $this->db->prepare($sql);
            $query->bindValue('cid', $consumerId, PDO::PARAM_INT);
            $query->bindValue('ctx', $contextId, PDO::PARAM_INT);
            $query->bindValue('rlid', $resourceLink->getId(), PDO::PARAM_STR);
            $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
            $query->bindValue('prlid', $primaryResourceLinkId, PDO::PARAM_INT);
            $query->bindValue('share_approved', $resourceLink->shareApproved, PDO::PARAM_INT);
            $query->bindValue('created', $now, PDO::PARAM_STR);
            $query->bindValue('updated', $now, PDO::PARAM_STR);
        } else if (!is_null($contextId)) {
            $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' SET ' .
                   'consumer_pk = NULL, context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, '.
                   'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' .
                   'WHERE (resource_link_pk = :id)';
            $query = $this->db->prepare($sql);
            $query->bindValue('ctx', $contextId, PDO::PARAM_INT);
            $query->bindValue('rlid', $resourceLink->getId(), PDO::PARAM_STR);
            $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
            $query->bindValue('prlid', $primaryResourceLinkId, PDO::PARAM_INT);
            $query->bindValue('share_approved', $resourceLink->shareApproved, PDO::PARAM_INT);
            $query->bindValue('updated', $now, PDO::PARAM_STR);
            $query->bindValue('id', $id, PDO::PARAM_INT);
        } else {
            $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' SET ' .
                   'context_pk = :ctx, lti_resource_link_id = :rlid, settings = :settings, '.
                   'primary_resource_link_pk = :prlid, share_approved = :share_approved, updated = :updated ' .
                   'WHERE (consumer_pk = :cid) AND (resource_link_pk = :id)';
            $query = $this->db->prepare($sql);
            $query->bindValue('ctx', $contextId, PDO::PARAM_INT);
            $query->bindValue('rlid', $resourceLink->getId(), PDO::PARAM_STR);
            $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
            $query->bindValue('prlid', $primaryResourceLinkId, PDO::PARAM_INT);
            $query->bindValue('share_approved', $resourceLink->shareApproved, PDO::PARAM_INT);
            $query->bindValue('updated', $now, PDO::PARAM_STR);
            $query->bindValue('cid', $consumerId, PDO::PARAM_INT);
            $query->bindValue('id', $id, PDO::PARAM_INT);
        }
        $ok = $query->execute();
        if ($ok) {
            if (empty($id)) {
                $resourceLink->setRecordId(intval($this->db->lastInsertId()));
                $resourceLink->created = $time;
            }
            $resourceLink->updated = $time;
        }

        return $ok;

    }