PHPackages                             phrity/net-uri - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. phrity/net-uri

ActiveLibrary[HTTP &amp; Networking](/categories/http)

phrity/net-uri
==============

PSR-7 Uri and PSR-17 UriFactory implementation

2.2.1(6mo ago)910.8M↓35.1%24MITPHPPHP ^8.1CI passing

Since Oct 25Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/sirn-se/phrity-net-uri)[ Packagist](https://packagist.org/packages/phrity/net-uri)[ Docs](https://phrity.sirn.se/net-uri)[ RSS](/packages/phrity-net-uri/feed)WikiDiscussions v2-main Synced 1w ago

READMEChangelog (9)Dependencies (8)Versions (10)Used By (4)

[![Phrity Net Uri](docs/logotype.png)](docs/logotype.png)

[![Build Status](https://github.com/sirn-se/phrity-net-uri/actions/workflows/acceptance.yml/badge.svg)](https://github.com/sirn-se/phrity-net-uri/actions)[![Coverage Status](https://camo.githubusercontent.com/07fb6c25b40cf7ed866f99d709e5d3ac6c3e5c477b6b31df24636ce60f6f24dd/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7369726e2d73652f7068726974792d6e65742d7572692f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/sirn-se/phrity-net-uri?branch=main)

Introduction
============

[](#introduction)

Implementation of the [PSR-7 UriInterface](https://www.php-fig.org/psr/psr-7/#35-psrhttpmessageuriinterface)and [PSR-17 UriFactoryInterface](https://www.php-fig.org/psr/psr-17/#26-urifactoryinterface) interfaces.

Nothing fancy. Just working. Because I need a URI implementation **not** hardwired to HTTP messaging. And some extras. Allow all valid schemes.

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

[](#installation)

Install with [Composer](https://getcomposer.org/);

```
composer require phrity/net-uri

```

Uri class methods
-----------------

[](#uri-class-methods)

Implemts [PSR-7 UriInterface](https://www.php-fig.org/psr/psr-7/#35-psrhttpmessageuriinterface)and provides some extra metods and options. [More info here](docs/Uri.md).

```
use Phrity\Net\Uri;
$uri = new Uri('http://example.com/path/to/file.html?query1=1#fragment');

// PSR-7 getters
$uri->getScheme();
$uri->getHost();
$uri->getPort();
$uri->getPath();
$uri->getQuery();
$uri->getFragment();
$uri->getAuthority();
$uri->getUserInfo();

// PSR-7 setters
$uri->withScheme('https');
$uri->withHost('example2.com');
$uri->withPort(8080);
$uri->withPath('/path/to/another/file.html');
$uri->withQuery('query2=2');
$uri->withFragment('another-fragment');
$uri->withUserInfo('username', 'password');

// Equalable implementation
$uri->equals('http://example.com/path/to/file.html');

// Stringable implementation
$uri->__toString();

// JsonSerializable implementation
$uri->jsonSerialize();

// Additional methods
$uri->toString();
$uri->getQueryItems();
$uri->getQueryItem('query1');
$uri->withQueryItems(['query1' => '1', 'query2' => '2']);
$uri->withQueryItem('query1', '1');
$uri->getComponents();
$uri->withComponents(['scheme' => 'https', 'host' => 'example2.com']);
```

UriFactory class methods
------------------------

[](#urifactory-class-methods)

Implemts [PSR-17 UriFactoryInterface](https://www.php-fig.org/psr/psr-17/#26-urifactoryinterface)and provides some extra metods and options. [More info here](docs/UriFactory.md).

```
use Phrity\Net\UriFactory;
$factory = new UriFactory();
$factory->createUri('http://example.com/path/to/file.html');
$factory->createUriFromInterface(new GuzzleHttp\Psr7\Uri('http://example.com/path/to/file.html'));
```

Modifiers
---------

[](#modifiers)

Out of the box, it will behave as specified by PSR standards. To change behaviour, there are some modifiers available. These can be added as last argument in all `get` and `with` methods, plus the `toString` method.

- `REQUIRE_PORT` - Attempt to show port, even if default
- `ABSOLUTE_PATH` - Will cause path to use absolute form, i.e. starting with `/`
- `NORMALIZE_PATH` - Will attempt to normalize path
- `IDN_ENCODE` / `IDN_DECODE` - Encode or decode IDN-format for non-ASCII host
- `URI_DECODE` / `URI_ENCODE` / `URI_ENCODE_3986` - Encode or decode URI components

### Examples

[](#examples)

```
$uri = new Uri('http://example.com');
$uri->getPort(Uri::REQUIRE_PORT); // => 80
$uri->toString(Uri::REQUIRE_PORT); // => 'http://example.com:80'

$uri = new Uri('a/./path/../to//something');
$uri->getPath(Uri::ABSOLUTE_PATH | Uri::NORMALIZE_PATH); // => '/a/to/something'
$uri->toString(Uri::ABSOLUTE_PATH | Uri::NORMALIZE_PATH); // => '/a/to/something'

$clone = $uri->withPath('path/./somewhere/else/..', Uri::ABSOLUTE_PATH | Uri::NORMALIZE_PATH);
$clone->getPath(); // => '/path/somewhere'

$uri = new Uri('https://ηßöø必Дあ.com');
$uri->getHost(Uri::IDN_ENCODE); // => 'xn--zca0cg32z7rau82strvd.com'
```

Versions
--------

[](#versions)

VersionPHP`2.2``^8.1`Equable implementation`2.1``^8.0`URI encode/decode options`2.0``^8.0`Query helpers, with(\[\]) and getComponents() methods, IDN encode/decode`1.3``^7.4|^8.0``1.2``^7.4|^8.0`IDNA modifier`1.1``^7.4|^8.0`Require port, Absolute path, Normalize path modifiers`1.0``^7.4|^8.0`Initial version

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance68

Regular maintenance activity

Popularity53

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 97.7% 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

Every ~142 days

Recently: every ~160 days

Total

9

Last Release

186d ago

Major Versions

1.3.0 → 2.0.02024-03-03

PHP version history (4 changes)1.0.0PHP ^7.4|^8.0

1.3.0PHP ^7.4 | ^8.0

2.0.0PHP ^8.0

2.2.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4255391?v=4)[Sören Jensen](/maintainers/sirn-se)[@sirn-se](https://github.com/sirn-se)

---

Top Contributors

[![sirn-se](https://avatars.githubusercontent.com/u/4255391?v=4)](https://github.com/sirn-se "sirn-se (43 commits)")[![simPod](https://avatars.githubusercontent.com/u/327717?v=4)](https://github.com/simPod "simPod (1 commits)")

---

Tags

phpphp-librarypsr-17psr-7uripsr-7uripsr-17uri factory

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phrity-net-uri/health.svg)

```
[![Health](https://phpackages.com/badges/phrity-net-uri/health.svg)](https://phpackages.com/packages/phrity-net-uri)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B3.7k](/packages/guzzlehttp-psr7)[cakephp/cakephp

The CakePHP framework

8.8k19.1M1.7k](/packages/cakephp-cakephp)[symfony/psr-http-message-bridge

PSR HTTP message bridge

1.3k312.3M926](/packages/symfony-psr-http-message-bridge)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k11](/packages/tempest-framework)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28146.3k](/packages/phpro-http-tools)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

577.0M94](/packages/laminas-laminas-stratigility)

PHPackages © 2026

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