public function parse($uri)
    {
        if (!$this->isValidString($uri)) {
            return null;
        }

        $pattern = new UriPattern();
        $pattern->allowNonAscii($this->mode !== self::MODE_RFC3986);

        if ($pattern->matchUri($uri, $match)) {
            try {
                return $this->buildUri($match);
            } catch (\InvalidArgumentException $exception) {
                return null;
            }
        }

        return null;
    }