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

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

nsaliu/laravel-uri
==================

A URI component for Laravel framework

1.0.0(6y ago)04MITPHPPHP ^7.2CI failing

Since Jan 24Pushed 6y ago1 watchersCompare

[ Source](https://github.com/nsaliu/laravel-uri)[ Packagist](https://packagist.org/packages/nsaliu/laravel-uri)[ Docs](https://github.com/nsaliu/laravel-uri)[ RSS](/packages/nsaliu-laravel-uri/feed)WikiDiscussions develop Synced 2d ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Laravel URI package
===================

[](#laravel-uri-package)

[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![CircleCI](https://camo.githubusercontent.com/99c2d63364922a27f25f3db8b1458c11abd6548250d958fa62d5bd3167506c8a/68747470733a2f2f696d672e736869656c64732e696f2f636972636c6563692f6275696c642f67682f6e73616c69752f6c61726176656c2d7572692f6d61737465723f7374796c653d666c61742d737175617265)](https://circleci.com/gh/nsaliu/laravel-uri/tree/master)[![StyleCI](https://camo.githubusercontent.com/7b466efc4cf5f5ed2b5bd16f61d91079d2ae6040447513c4b2ac3dfe36a7412c/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3233353833373435352f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/235837455)

A simple and useful URI package for Laravel framework.

This package provides an object representation of a uniform resource identifier (URI), an easy access and manipulation to the parts of the URI.

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

[](#installation)

This package requires PHP 7.2 and Laravel 5.8 or higher.

Install with composer:

`composer require nsaliu/laravel-uri`

Methods
-------

[](#methods)

### createFromString

[](#createfromstring)

Creates a new instance with the specified URI.

```
$uri = new Uri();
$uri->createFromString('https://test.test');

```

### toString

[](#tostring)

Return the string representation of the URI instance.

```
$uri = new Uri();
$uri->createFromString('https://test.test');
$uri->toString();

```

### hostIsReachable

[](#hostisreachable)

Check with a GET call if the host returns an HTTP status code equals to 200.

```
$uri = new Uri();
$uri->createFromString('https://test.test');
$uri->hostIsReachable();

```

### equals

[](#equals)

Check if a string representation of the URI equals to the URI instance.

```
$uri = new Uri();
$uri->createFromString('https://test.test');
$uri->equals('https://test.test');

```

### getComponents

[](#getcomponents)

Gets all the URIs components if presents.

```
$uri = new Uri();
$uri->createFromString('https://fakeuser:fakepass@test.test:443/path1/path2/page.html?key1=value1&key2=value2#fragment');
$uri->getComponents();

```

Return:

```
[
  'scheme' => 'https'
  'host' => 'test.test'
  'port' => 443
  'user' => 'fakeuser'
  'pass' => 'fakepass'
  'path' => '/path1/path2/page.html'
  'query' => 'key1=value1&key2=value2'
  'fragment' => 'fragment'
]

```

Getters
-------

[](#getters)

### getScheme

[](#getscheme)

Get the scheme part of the URI.

```
$uri = new Uri();
$uri->createFromString('https://test.test');
$uri->getScheme();

```

If a scheme is present return `https` otherwise an `empty string`.

### getUsername

[](#getusername)

Get the user part of the URI.

```
$uri = new Uri();
$uri->createFromString('https://fakeuser:fakepass@test.test');
$uri->getUsername();

```

If a user is present returns `fakeuser`, otherwise return an `empty string`.

### getPassword

[](#getpassword)

Get the pass part of the URI.

```
$uri = new Uri();
$uri->createFromString('https://fakeuser:fakepass@test.test');
$uri->getPassword();

```

If a password is set return `fakepass`, otherwise return an `empty string`.

### getAuthority

[](#getauthority)

Get the authority part of the URI.

```
$uri = new Uri();
$uri->createFromString('https://fakeuser:fakepass@test.test');
$uri->getAuthority();

```

Return:

- if no authority information is present, this method return an `empty string`.
- if authority is set return it in form of: `jhon:doe@test.com`.
- if the port is a standard port for scheme, the port is not included, otherwise yes.

Example:

```
// Create a URI with 'https' scheme and '80' as port (not default for https)
$uri = new Uri();
$uri->createFromString('https://fakeuser:fakepass@test.test');
$uri->getAuthority();

```

Return `jhon:doe@test.com:80`

### getAuthorityWithPort

[](#getauthoritywithport)

Get the authority part of the URI with the port too, even if it's the default for the scheme.

```
$uri = new Uri();
$uri->createFromString('https://fakeuser:fakepass@test.test:443');
$uri->getAuthorityWithPort();

```

Return `jhon:doe@test.com:443`

### getUserInfo

[](#getuserinfo)

Get the user part of the URI.

```
$uri = new Uri();
$uri->createFromString('https://fakeuser:fakepass@test.test:443');
$uri->getUserInfo();

```

Return:

- if no user information is present return an `empty string`.
- if a user is present in the URI return `fakeuser`.
- if a password is present it returns the password too separated by ':' from the username `fakeuser:fakepass`

### getHost

[](#gethost)

Get the host part of the URI.

```
$uri = new Uri();
$uri->createFromString('https://test.test');
$uri->getHost();

```

Return `test.test`

### getPort

[](#getport)

Get the port part of the URI.

```
$uri = new Uri();
$uri->createFromString('https://test.test:443');
$uri->getPort();

```

Return:

- if the port is present return the port as an integer: `443`.
- if the port is not present, return `null`.

### isDefaultPort

[](#isdefaultport)

Get whether the port value of the URI is the default for the scheme.

```
$uri = new Uri();
$uri->createFromString('https://test.test:80');
$uri->isDefaultPort();

// return false because 80 isn't the default port for https scheme

```

Return:

- `true` if the port is default for the scheme.
- `false` if the port isn't the default.

### getPath

[](#getpath)

Get the path value of the URI.

```
$uri = new Uri();
$uri->createFromString('https://test.test/path1/path2/page.html');
$uri->getPath();

```

Return:

- if a path is present return `/path1/path2/page.html`.
- if the path is not present return an `empty string`.

### getPathAsArray

[](#getpathasarray)

Get the path value of the URI as an array.

```
$uri = new Uri();
$uri->createFromString('https://test.test/path1/path2/page.html');
$uri->getPathAsArray();

```

Return:

- if the path is present return the path portion of the URI as an array:

```
[
    'path1',
    'path2',
    'page.html',
]

```

- if path is not present return an `empty string`.

### getQuery

[](#getquery)

Get the query part of the URI.

```
$uri = new Uri();
$uri->createFromString('https://test.test/path1/path2/page.html?key1=value1&key2=value2');
$uri->getQuery();

```

Return:

- if the query part of the URI is present return `key1=value1&key2=value2`.
- if the query part of the URI is not present return an `empty string`.

### getQueryValue

[](#getqueryvalue)

Get the value of a given query key.

```
$uri = new Uri();
$uri->createFromString('https://test.test/path1/path2/page.html?key1=value1&key2=value2');
$uri->getQueryValue('key1');

```

Return:

- if the key exists in query return: `value1`.
- if the key not exists in query part return an `empty string`.

### getQueryAsArray

[](#getqueryasarray)

Get the query part of the URI as an array.

```
$uri = new Uri();
$uri->createFromString('https://test.test/path1/path2/page.html?key1=value1&key2=value2');
$uri->getQueryAsArray();

```

Return:

- if the query part is present return:

```
[
    'key1' => 'value1',
    'key2' => 'value2',
]

```

- if the query part not exists return an `empty array`.

### getPathAndQuery

[](#getpathandquery)

Get the path and query part of the URI.

```
$uri = new Uri();
$uri->createFromString('https://test.test/path1/path2/page.html?key1=value1&key2=value2');
$uri->getPathAndQuery();

```

Return:

- if the path and query exists return `/path1/path2/page.html?key1=value1&key2=value2`.
- if the path exists and query not exists return `/path1/path2/page.html`.
- if the path not exists and query too return an `empty string`.

### getFragment

[](#getfragment)

Get the fragment part of the URI.

```
$uri = new Uri();
$uri->createFromString('https://test.test/page.html?key1=value1&key2=value2#fragment-1');
$uri->getFragment();

```

Return:

- if the fragment is present return `fragment-1`.
- if the fragment is not present return an `empty string`.

Setters
-------

[](#setters)

### setScheme

[](#setscheme)

Set the scheme part of the URI.

```
$uri = new Uri();
$uri->setScheme('http');

```

### setUsername

[](#setusername)

Set the user part of the URI.

```
$uri = new Uri();
$uri->setUsername('username');

```

### setPassword

[](#setpassword)

Set the password part of the URI.

```
$uri = new Uri();
$uri->setPassword('password');

```

### setUserInfo

[](#setuserinfo)

Set the user and password part of the URI.

```
$uri = new Uri();
$uri->setUserInfo('username'); // without password
$uri->setUserInfo('username', 'password'); // or with password

```

### setHost

[](#sethost)

Set the host part of the URI.

```
$uri = new Uri();
$uri->setHost('test.test');

```

### setPort

[](#setport)

Set the port part of the URI.

```
$uri = new Uri();
$uri->setPort(80);

```

### setPath

[](#setpath)

Set the path part of the URI.

```
$uri = new Uri();
$uri->setPath('path1/path2/page.html');

```

### setQuery

[](#setquery)

Set the query part of the URI.

```
$uri = new Uri();
$uri->setQuery('key1&value1&key2=value2');

```

### setQueryArray

[](#setqueryarray)

Set the query part of the URI with an array.

```
$uri = new Uri();
$uri->setQueryArray(['key1' => 'value1', 'key2' => 'value2']);

```

### addQuery

[](#addquery)

Add a query key and value to the URI.

```
$uri = new Uri();
$uri->addQuery('key3', 'value3');

```

### changeQuery

[](#changequery)

Change a query part of the URI.

```
$uri = new Uri();
$uri->changeQuery('key1', 'new-value');

```

### setFragment

[](#setfragment)

Set the fragment part of the URI.

```
$uri = new Uri();
$uri->setFragment('fragment-2');

```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

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

2301d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/74f451a71b21c6228f043273d23b5ef0dec5408921acefefe8176f5268dc2b30?d=identicon)[nsaliu](/maintainers/nsaliu)

---

Top Contributors

[![nsaliu](https://avatars.githubusercontent.com/u/2877876?v=4)](https://github.com/nsaliu "nsaliu (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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