public function formatUrl(array $parameters = []): string
    {
        $values = [];

        foreach ($this->parameterNames as $name) {
            if (!isset($parameters[$name])) {
                throw new \InvalidArgumentException("Missing route parameter '$name'");
            }

            $values[] = rawurlencode($parameters[$name]);
            unset($parameters[$name]);
        }

        if (!empty($parameters)) {
            throw new \InvalidArgumentException(
                'Unexpected route parameters: ' . implode(', ', array_keys($parameters))
            );
        }

        return vsprintf($this->format, $values);
    }