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
Requires
- php: ^8.1
- symfony/http-foundation: ^6.1 || ^7.0 || ^8.0
Requires (Dev)
- contao/easy-coding-standard: ^6.13
README
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 } }
