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

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

gravitymedia/uri
================

A PHP library for generating RFC 3986 compliant uniform resource identifiers (URI).

v0.2.0(9y ago)032MITPHPPHP &gt;=5.6

Since Mar 8Pushed 9y ago1 watchersCompare

[ Source](https://github.com/GravityMedia/Uri)[ Packagist](https://packagist.org/packages/gravitymedia/uri)[ RSS](/packages/gravitymedia-uri/feed)WikiDiscussions master Synced 1mo ago

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

Uniform Resource Identifier (URI)
=================================

[](#uniform-resource-identifier-uri)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7c92c4eace6f3ed67bbab25c636bfdc31ed6efe7b96838e2074490739dbd066e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677261766974796d656469612f7572692e737667)](https://packagist.org/packages/gravitymedia/uri)[![Software License](https://camo.githubusercontent.com/5b1f8b0a0c6d008a3d2d9418a6263dc5b13e3037ed4c8365d35bca8e87b1ba87/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f677261766974796d656469612f7572692e737667)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/830b3ccbe4ccb2d941adba642217bd07e91f60b2984f972d74e21c7d56c4daeb/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f477261766974794d656469612f5572692e737667)](https://travis-ci.org/GravityMedia/Uri)[![Coverage Status](https://camo.githubusercontent.com/ed333e9a6b8717bba3a93bbfb9b321495276bd82a089ae2fee432bec65cf5889/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f477261766974794d656469612f5572692e737667)](https://scrutinizer-ci.com/g/GravityMedia/Uri/code-structure)[![Quality Score](https://camo.githubusercontent.com/c8808024f7b0d56b6f6fce8bdc6c5bf796e0818b7d9b838519f8806b7a490868/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f477261766974794d656469612f5572692e737667)](https://scrutinizer-ci.com/g/GravityMedia/Uri)[![Total Downloads](https://camo.githubusercontent.com/0ca54b4412a93370eb999768025b4234bdc0c603ba2088770e5f36cfea028a2f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f677261766974796d656469612f7572692e737667)](https://packagist.org/packages/gravitymedia/uri)[![Dependency Status](https://camo.githubusercontent.com/2e706db8bd5fa0359307dd5294dafbc0b3fb2adf3fd65bcb5f4dcc9c5615bd4e/68747470733a2f2f696d672e736869656c64732e696f2f76657273696f6e6579652f642f7068702f677261766974796d656469613a7572692e737667)](https://www.versioneye.com/user/projects/54fcb6ba4f31084fdc000719)

A PHP library for generating RFC 3986 compliant uniform resource identifiers (URI).

Requirements
------------

[](#requirements)

This library has the following requirements:

- PHP 5.6+

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

[](#installation)

Install Composer in your project:

```
$ curl -s https://getcomposer.org/installer | php
```

Require the package via Composer:

```
$ php composer.phar require gravitymedia/uri
```

Usage
-----

[](#usage)

This example illustrates te basic usage of an URI object.

```
// require autoloader
require 'vendor/autoload.php';

// import classes
use GravityMedia\Uri\Uri;

// create URI object from string
$uri = Uri::fromString('http://username:password@example.com:8080/this/is/a/path?argument=value#my_fragment');

// dump scheme
var_dump($uri->getScheme()); // string(4) "http"

// dump authority
var_dump($uri->getAuthority()); // string(29) "username:password@example.com"

// dump user info
var_dump($uri->getUserInfo()); // string(17) "username:password"

// dump host
var_dump($uri->getHost()); // string(11) "example.com"

// dump port
var_dump($uri->getPort()); // int(8080)

// dump path
var_dump($uri->getPath()); // string(15) "/this/is/a/path"

// dump argument
var_dump($uri->getQuery()); // string(14) "argument=value"

// dump fragment
var_dump($uri->getFragment()); // string(11) "my_fragment"

// remove path and remove fragment
$uri = $uri->withPath('')->withFragment('');

// dump URI
var_dump($uri->toString()); // string(56) "http://username:password@example.com:8080?argument=value"
```

The URI also supports URN syntax.

```
// require autoloader
require 'vendor/autoload.php';

// import classes
use GravityMedia\Uri\Uri;

// create URI object from string
$uri = Uri::fromString('urn:example:animal:ferret:nose');

// dump scheme
var_dump($uri->getScheme()); // string(3) "urn"

// dump path
var_dump($uri->getPath()); // string(26) "example:animal:ferret:nose"
```

Use the `SchemeRegistry` to support additional schemes and normalize the the URI string.

```
// require autoloader
require 'vendor/autoload.php';

// import classes
use GravityMedia\Uri\SchemeRegistry;
use GravityMedia\Uri\Uri;

// register SSH scheme
SchemeRegistry::registerSchemes([
    'ssh' => 22,
]);

// create URI object from string
$uri = Uri::fromString('ssh://git@github.com:22/GravityMedia/Uri.git');

// dump normalized URI
var_dump($uri->toString()); // string(41) "ssh://git@github.com/GravityMedia/Uri.git"
```

The `AbstractQuery` class allows to define and manipulate the query string.

```
// require autoloader
require 'vendor/autoload.php';

// import classes
use GravityMedia\Uri\AbstractQuery;
use GravityMedia\Uri\Uri;

/**
 * My query class.
 */
class MyQuery extends AbstractQuery
{
    /**
     * The argument.
     *
     * @var mixed
     */
    protected $argument;

    /**
     * Get argument.
     *
     * @return mixed
     */
    public function getArgument()
    {
        return $this->argument;
    }

    /**
     * Set argument.
     *
     * @param mixed $argument
     *
     * @return $this
     */
    public function setArgument($argument)
    {
        $this->argument = $argument;

        return $this;
    }
}

// create URI object from string
$uri = Uri::fromString('http://example.com?argument=value');

// create my query object from string
$query = MyQuery::fromString($uri->getQuery());

// dump array representation of query
var_dump($query->toArray()); // array(1) { ["argument"]=> string(5) "value" }

// update query argument value
var_dump($query->setArgument('new value')->toString()); // string(18) "argument=new+value"

// change query
$uri = $uri->withQuery($query->toString());

// dump URI
var_dump($uri->toString()); // string(37) "http://example.com?argument=new+value"
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

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 ~240 days

Total

3

Last Release

3609d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.3.3

v0.2.0PHP &gt;=5.6

### Community

Maintainers

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/gravitymedia-uri/health.svg)](https://phpackages.com/packages/gravitymedia-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)
