PHPackages                             bentools/uri-factory - 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. bentools/uri-factory

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

bentools/uri-factory
====================

PSR-7 URI factory

2.4(1y ago)426.4k↓82.8%5MITPHPPHP &gt;=8.0CI failing

Since Nov 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bpolaszek/uri-factory)[ Packagist](https://packagist.org/packages/bentools/uri-factory)[ RSS](/packages/bentools-uri-factory/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (11)Versions (11)Used By (5)

[![Latest Stable Version](https://camo.githubusercontent.com/0f632b014b42845031b2aaddeb89296b9af9d14e241b87fc68596f048db47888/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f7572692d666163746f72792f762f737461626c65)](https://packagist.org/packages/bentools/uri-factory)[![License](https://camo.githubusercontent.com/2518c64cf1addd79050f4bc43c989cd6b83937f7f992a85f8d700c5606781f02/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f7572692d666163746f72792f6c6963656e7365)](https://packagist.org/packages/bentools/uri-factory)[![Build Status](https://camo.githubusercontent.com/577e4ec20927722db106a6a197d345087b46bf09f919ce954af6a38c89a6eb36/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f62706f6c61737a656b2f7572692d666163746f72792f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/bpolaszek/uri-factory)[![Coverage Status](https://camo.githubusercontent.com/877ec3b78007edf96783ed29a3fa390c36ee6ee442d7c011f2056e11b244ce13/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f62706f6c61737a656b2f7572692d666163746f72792f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/bpolaszek/uri-factory?branch=master)[![Quality Score](https://camo.githubusercontent.com/4515c39c816259d13dcf704aa000015bdd947252055b18013c18b1dbd9419cf3/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f62706f6c61737a656b2f7572692d666163746f72792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bpolaszek/uri-factory)[![Total Downloads](https://camo.githubusercontent.com/2875cbbe2531ad06b0b897a479646dc9f781515951149dcbd53f796c7d0096a1/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f7572692d666163746f72792f646f776e6c6f616473)](https://packagist.org/packages/bentools/uri-factory)

Uri Factory
===========

[](#uri-factory)

A library / framework agnostic PSR-7 `UriInterface` factory.

There are several PSR-7 libraries on packagist but each one has its own factory for creating an `UriInterface` object from a string.

[bentools/uri-factory](https://github.com/bpolaszek/uri-factory) has no explicit dependency and automatically picks up your favorite library for creating `UriInterface` instances.

Supported libraries so far:

- `guzzlehttp/psr7`
- `league/uri`
- `nyholm/psr7`
- `ringcentral/psr7`

Usage
-----

[](#usage)

On any URL string:

```
use function BenTools\UriFactory\Helper\uri;
$uri = uri('http://www.example.net'); // Will convert to a Psr\Http\Message\UriInterface instance
```

On current location:

```
use function BenTools\UriFactory\Helper\current_location;
$uri = current_location(); // Will convert the current location to a Psr\Http\Message\UriInterface instance
```

You can specify which library to use, by using the corresponding adapter:

```
use BenTools\UriFactory\Adapter\GuzzleAdapter;
use BenTools\UriFactory\Adapter\LeagueUriAdapter;
use function BenTools\UriFactory\Helper\current_location;
use function BenTools\UriFactory\Helper\uri;

$uri = uri('http://www.example.net', GuzzleAdapter::factory());
$uri = uri('http://www.example.net', LeagueUriAdapter::factory());

$uri = current_location(GuzzleAdapter::factory());
$uri = current_location(LeagueUriAdapter::factory());
```

Canonicalizer
-------------

[](#canonicalizer)

This library ships with an URL canonicalizer.

It is not a perfect one since your PSR-7 library may behave differently regarding special chars, but it should work most of the time.

The `canonicalize()` function accepts any PSR-7 `UriInterface` object and will return a canonicalized one.

```
require_once __DIR__ . '/vendor/autoload.php';

use function BenTools\UriFactory\Helper\canonicalize;
use function BenTools\UriFactory\Helper\uri;

$url = 'http://example.org../foo/../bar/?#baz';
echo canonicalize(uri($url)); // http://example.org/bar/
```

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

[](#installation)

PHP 8.0+ is required.

> composer require bentools/uri-factory

Tests
-----

[](#tests)

> ./vendor/bin/phpunit

Contribute
----------

[](#contribute)

If you want [bentools/uri-factory](https://github.com/bpolaszek/uri-factory) to support more PSR-7 libraries, feel free to submit a PR.

License
-------

[](#license)

MIT.

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance47

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 90% 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 ~306 days

Recently: every ~526 days

Total

10

Last Release

394d ago

Major Versions

1.1 → 2.02018-08-31

PHP version history (2 changes)1.0PHP &gt;=7.1

2.3PHP &gt;=8.0

### Community

Maintainers

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

---

Top Contributors

[![bpolaszek](https://avatars.githubusercontent.com/u/5569077?v=4)](https://github.com/bpolaszek "bpolaszek (18 commits)")[![misaert](https://avatars.githubusercontent.com/u/12974251?v=4)](https://github.com/misaert "misaert (2 commits)")

---

Tags

psr-7urlurifactorypsr7UriInterface

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/bentools-uri-factory/health.svg)

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[league/uri

URI manipulation library

1.1k240.0M391](/packages/league-uri)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

539238.7M44](/packages/league-uri-interfaces)[mezzio/mezzio

PSR-15 Middleware Microframework

3923.8M125](/packages/mezzio-mezzio)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)

PHPackages © 2026

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