private function buildUri(array $components)
    {
        $uri = new Uri();

        if (isset($components['reg_name'])) {
            $components['host'] = $this->decodeHost($components['host']);
        }

        foreach (array_intersect_key(self::$setters, $components) as $key => $method) {
            $uri = call_user_func([$uri, $method], $components[$key]);
        }

        if (isset($components['userinfo'])) {
            list($username, $password) = preg_split('/:|$/', $components['userinfo'], 2);
            $uri = $uri->withUserInfo(rawurldecode($username), rawurldecode($password));
        }

        return $uri;
    }