PHPackages                             dealnews/url - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dealnews/url

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dealnews/url
============

URL Parser and Builder

1.0.0(6mo ago)00BSD-3-ClausePHPPHP ^8.2CI passing

Since Nov 8Pushed 1mo agoCompare

[ Source](https://github.com/dealnews/url)[ Packagist](https://packagist.org/packages/dealnews/url)[ RSS](/packages/dealnews-url/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

DealNews URL Utilities
======================

[](#dealnews-url-utilities)

Utilities for parsing, normalizing, merging, and building URLs with fine‑grained control over query strings.

Installation
------------

[](#installation)

```
composer require dealnews/url
```

Classes
-------

[](#classes)

### DealNews\\Url\\Url

[](#dealnewsurlurl)

High level URL helper that stores individual URL parts (`scheme`, `host`, `path`, `query`, etc.) and keeps a `QueryString` helper in sync with the `query` property.

Key capabilities:

- `parse(string $url, bool $reset = true, ?string $separator = null)` – split a URL into parts and validate each component.
- Magic setters/getters (`$url->host`, `$url->path`, `$url->query`, …) – allow direct manipulation of parts with validation.
- `build(?string $separator = null)` – rebuild the URL, omitting default ports and honoring custom separators.
- `normalize()` – lowercases scheme/host, sorts query parameters, and normalizes percent‑encoding.
- `sanitizePathComponent(string $input)` – generate safe slug/path fragments.
- `merge(string $url1, string ...$url2)` – merge one or more URLs into the current instance without mutating the original data.

Example:

```
use DealNews\Url\Url;

$url = new Url('https://user:pass@example.com:443/products/tv?q=4k#details');
$url->normalize(); // lowercases scheme/host and sorts query parameters

$url->query_string->setParameter('page', '2');
$url->fragment = 'reviews';

echo $url->build(); // https://user:pass@example.com/products/tv?q=4k&page=2#reviews

// Merge additional data without losing the existing state
$combined = $url->merge('http://cdn.example.com/media', '?size=large');
// $combined => http://cdn.example.com/media?size=large
// $url remains unchanged
```

### DealNews\\Url\\QueryString

[](#dealnewsurlquerystring)

Lightweight parser/builder for ordered query strings. Allows unnamed entries, custom separators, front insertion, and selective replacement.

Key methods:

- `parse(string $query_string, string $separator = '&')`
- `build(?string $separator = null): string`
- `addParameter(?string $key, ?string $value, bool $front = false)`
- `setParameter(?string $key, ?string $value, bool $front = false)`
- `removeParameters(array $keys): void`
- `sortParameters(): void`
- `getParameters(): array`

Example:

```
use DealNews\Url\QueryString;

$qs = new QueryString('foo=1&bar=2');
$qs->setParameter('foo', '3');
$qs->addParameter(null, 'feature'); // unnamed flag
$qs->sortParameters(); // only sorts when all params are named

echo $qs->build(); // foo=3&bar=2&feature
```

Custom separator example:

```
$qs = new QueryString(null, ';');
$qs->parse('token;user=john;role=admin', ';');
$qs->addParameter('expires', '1700000000');

echo $qs->build(); // token;user=john;role=admin;expires=1700000000
```

### DealNews\\Url\\Exception\\Parse

[](#dealnewsurlexceptionparse)

Custom exception extending `\Exception`. Methods such as `Url::__construct()` and `Url::__set()` throw `Parse` when a URL cannot be parsed or an invalid property is referenced.

```
use DealNews\Url\Exception\Parse;
use DealNews\Url\Url;

try {
    $url = new Url();
    $url->invalid_property = 'value';
} catch (Parse $e) {
    // Handle invalid assignment
}
```

Testing
-------

[](#testing)

```
composer install
./vendor/bin/phpunit
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance81

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

190d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/49531?v=4)[Brian Moon](/maintainers/brianlmoon)[@brianlmoon](https://github.com/brianlmoon)

![](https://www.gravatar.com/avatar/dbf067b8b1b679cc96fb0e13483a6be5b90cb35dfbb85d471cee151b9fa87417?d=identicon)[dealnews](/maintainers/dealnews)

---

Top Contributors

[![brianlmoon](https://avatars.githubusercontent.com/u/49531?v=4)](https://github.com/brianlmoon "brianlmoon (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![jearle-dealnews](https://avatars.githubusercontent.com/u/8784094?v=4)](https://github.com/jearle-dealnews "jearle-dealnews (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/dealnews-url/health.svg)

```
[![Health](https://phpackages.com/badges/dealnews-url/health.svg)](https://phpackages.com/packages/dealnews-url)
```

###  Alternatives

[ferdiunal/nova-editable-field

A Laravel Nova package to make fields editable.

104.6k](/packages/ferdiunal-nova-editable-field)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
