PHPackages                             byjg/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. byjg/uri

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

byjg/uri
========

A PHP implementation of PSR-7 UriInterface with additional utility methods

6.0.0(5mo ago)3564.9k—6.4%43MITPHPPHP &gt;=8.3 &lt;8.6CI passing

Since Feb 5Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/byjg/php-uri)[ Packagist](https://packagist.org/packages/byjg/uri)[ GitHub Sponsors](https://github.com/byjg)[ RSS](/packages/byjg-uri/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (23)Used By (3)

   sidebar\_key uri   tags    php

 http

    PSR-7 URI Implementation
========================

[](#psr-7-uri-implementation)

A PHP implementation of PSR-7 UriInterface with additional utility methods.

[![Sponsor](https://camo.githubusercontent.com/fab14b7f7f475072ada0473f193d6f322561fd4a2958e0cc89910d053347cf27/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53706f6e736f722d2532336561346161613f6c6f676f3d67697468756273706f6e736f7273266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d306431313137)](https://github.com/sponsors/byjg)[![Build Status](https://github.com/byjg/php-uri/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/php-uri/actions/workflows/phpunit.yml)[![Opensource ByJG](https://camo.githubusercontent.com/425c1bbccc0f292bf4d20569ae74a6b2e384fd648f1af8911bc61de9a8dcfc0b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f70656e736f757263652d62796a672d737563636573732e737667)](http://opensource.byjg.com)[![GitHub source](https://camo.githubusercontent.com/88e61eb211719144efdd570290a0456b6e13099c2df8d973f1bb43fe33bf0039/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4769746875622d736f757263652d696e666f726d6174696f6e616c3f6c6f676f3d676974687562)](https://github.com/byjg/php-uri/)[![GitHub license](https://camo.githubusercontent.com/5270ff9cb88dad7671422e25cdaba7bb3bee70bee3aade60ef5e230a54638cda/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f62796a672f7068702d7572692e737667)](https://opensource.byjg.com/license/)[![GitHub release](https://camo.githubusercontent.com/59659060d77528844ceb6e866d2724e5ad501498ce3e34f0c1109377d57cf407/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f62796a672f7068702d7572692e737667)](https://github.com/byjg/uri/releases/)

Features
--------

[](#features)

- Fully compliant with [PSR-7 UriInterface](https://github.com/php-fig/http-message/blob/master/src/UriInterface.php)
- Includes additional utility methods via CustomUriInterface
- Supports RFC3986 URI specification
- Type-safe implementation with PHP 8 attributes and strict typing
- Immutable class design pattern

URI Encoding Behavior
---------------------

[](#uri-encoding-behavior)

PSR-7 requires URI compliant with RFC3986. This means the URI output will always be URL encoded. This applies to both creating a new instance and the string representation.

Examples:

```
// Creating a URI with special characters in the password
$uri = \ByJG\Util\Uri::getInstance("https://user:pa&@host");
print((string)$uri); // Will print "https://user:pa%26@host"

// Creating a URI with already encoded characters
$uri = \ByJG\Util\Uri::getInstance("https://user:pa%26@host");
print((string)$uri); // Will print "https://user:pa%26@host"

// Using withUserInfo with unencoded password
$uri = \ByJG\Util\Uri::getInstance("https://host")
    ->withUserInfo("user", "pa&");
print((string)$uri); // Will print "https://user:pa&@host"

// Using withUserInfo with already encoded password
$uri = \ByJG\Util\Uri::getInstance("https://host")
    ->withUserInfo("user", "pa%26");
print((string)$uri); // Will print "https://user:pa%2526@host"
```

Additional Methods
------------------

[](#additional-methods)

This implementation extends PSR-7 UriInterface with the following additional methods through `\ByJG\Util\CustomUriInterface`:

MethodDescription`getUsername(): ?string`Get the username component of the URI`getPassword(): ?string`Get the password component of the URI`getQueryPart(string $key): ?string`Get a specific query parameter by key`withQueryKeyValue(string $key, string $value, bool $isEncoded = false): self`Add or update a query parameter`hasQueryKey(string $key): bool`Check if a query parameter existsStatic Factory Methods
----------------------

[](#static-factory-methods)

The class provides convenient static factory methods:

```
// Create from string
$uri = Uri::getInstance("https://example.com/path?query=value#fragment");

// Create from another UriInterface
$uri2 = Uri::getInstance($uri);
```

Documentation
-------------

[](#documentation)

- [Getting Started](docs/getting-started.md)
- [URI Encoding Behavior](docs/uri-encoding.md)
- [Additional Methods](docs/additional-methods.md)
- [PSR-7 Methods](docs/psr7-methods.md)
- [Factory Methods](docs/factory-methods.md)
- [Examples](docs/examples.md)

Install
-------

[](#install)

```
composer require "byjg/uri"
```

Unit tests
----------

[](#unit-tests)

```
vendor/bin/phpunit
```

Dependencies
------------

[](#dependencies)

 ```
flowchart TD
    byjg/uri --> psr/http-message
```

      Loading ---

[Open source ByJG](https://opensource.byjg.com)

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance79

Regular maintenance activity

Popularity41

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 94.2% 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 ~153 days

Recently: every ~98 days

Total

22

Last Release

174d ago

Major Versions

2.1.3 → 4.9.02022-06-15

4.9.0 → 5.0.02023-05-18

4.9.2 → 5.0.12024-06-09

4.9.x-dev → 5.0.22024-10-27

5.0.3 → 6.0.02025-11-25

PHP version history (5 changes)1.0.0PHP &gt;=5.4.0

5.0.0PHP &gt;=7.4

5.0.2PHP &gt;=8.1 &lt;8.4

5.0.x-devPHP &gt;=8.1 &lt;8.5

6.0.0PHP &gt;=8.3 &lt;8.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/981924?v=4)[Joao Gilberto Magalhaes](/maintainers/byjg)[@byjg](https://github.com/byjg)

---

Top Contributors

[![byjg](https://avatars.githubusercontent.com/u/981924?v=4)](https://github.com/byjg "byjg (113 commits)")[![PBXg33k](https://avatars.githubusercontent.com/u/1777196?v=4)](https://github.com/PBXg33k "PBXg33k (3 commits)")[![vitormattos](https://avatars.githubusercontent.com/u/1079143?v=4)](https://github.com/vitormattos "vitormattos (2 commits)")[![89409](https://avatars.githubusercontent.com/u/84925319?v=4)](https://github.com/89409 "89409 (1 commits)")[![cdenadai](https://avatars.githubusercontent.com/u/51721735?v=4)](https://github.com/cdenadai "cdenadai (1 commits)")

---

Tags

hacktoberfest

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

343121.4M79](/packages/google-cloud-core)[aimeos/aimeos-base

Aimeos base layer for abstracting from host environments

2.1k134.0k1](/packages/aimeos-aimeos-base)[phpgt/dom

Modern DOM API.

12412.2M18](/packages/phpgt-dom)[anthropic-ai/sdk

Anthropic PHP SDK

129134.7k5](/packages/anthropic-ai-sdk)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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