public function setUrl($url)
    {
        if (!is_string($url) && !is_array($url) && !(is_object($url) && method_exists($url, '__toString')))
        {
            throw new \UnexpectedValueException(
                'The url must be a array as returned by parse_url() a string or object implementing __toString(), "'.gettype($url).'" given.'
            );
        }

        if(!is_array($url)) {
            $parts = parse_url((string) $url);
        } else {
            $parts = $url;
        }

        if (is_array($parts)) {
            foreach ($parts as $key => $value) {
                $this->$key = $value;
            }
        }

        return $this;
    }