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;
                }));
            }
        }
    }