markocupic/url-util

Parse and manipulate urls in a Symfony Environment

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/markocupic/url-util

1.0.0 2025-12-13 20:46 UTC

This package is auto-updated.

Last update: 2025-12-13 20:48:06 UTC


README

Alt text

Url Util

A lightweight Symfony library that provides utility methods for working with URLs. It allows you to add or remove query parameters of a URL. If no URL is provided, the current request URL is used automatically.

✨ Features

  • Add query parameters to a URL
  • Remove one or more query parameters
  • Automatically falls back to the current request URL when no URL is passed
  • Cleans up encoded ampersands (&&)

📦 Installation

Install via Composer:

composer require markocupic/url-util

🚀 Usage

Inject the UrlUtil service into your controller or service:

class DemoController
{
    public function index(UrlUtil $urlUtil)
    {
        // Current request URL: https://example.com/page?foo=bar

        // Add a single query parameter
        $newUrl = $urlUtil->addQueryParam('foo_one', 'bar');
        // Result: https://example.com/page?foo_one=bar

        // Add an array parameter
        $newUrl = $urlUtil->addQueryParams('foo_two', 'biz,buz'], $newUrl);
        // Result: https://example.com/page?foo_one=bar&foo_two[]=biz&foo_two[]=buz

        // Remove one or more query parameters
        $url = 'https://example.com/page?foo=bar&baz=qux';
        $newUrl = $urlUtil->removeQueryParam(['foo'], $url);
        // Result: https://example.com/page?baz=qux
    }
}