fyre/uri

A URI library.

Installs: 315

Dependents: 3

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

pkg:composer/fyre/uri

v4.0.1 2025-11-02 10:28 UTC

README

FyreURI is a free, open-source immutable URI library for PHP.

Table Of Contents

Installation

Using Composer

composer require fyre/uri

In PHP:

use Fyre\Http\Uri;

Basic Usage

  • $uriString is a string representing the uri.
$uri = new Uri($uriString);

Alternatively, you can use the createFromString method for easier chaining.

$uri = Uri::createFromString($uriString);

Methods

Get Authority

Get the URI authority string.

$authority = $uri->getAuthority();

Get Fragment

Get the URI fragment.

$fragment = $uri->getFragment();

Get Host

Get the URI host.

$host = $uri->getHost();

Get Path

Get the URI path.

$path = $uri->getPath();

Get Port

Get the URI port.

$port = $uri->getPort();

Get Query

Get the URI query string.

$query = $uri->getQuery();

Get Query Params

Get the URI query params.

$params = $uri->getQueryParams();

Get Scheme

Get the URI scheme.

$scheme = $uri->getScheme();

Get Segment

Get a specified URI segment.

  • $segment is a number indicating the segment index.
$part = $uri->getSegment($segment);

Get Segments

Get the URI segments.

$segments = $uri->getSegments();

Get Total Segments

Get the URI segments count.

$segmentCount = $uri->getTotalSegments();

Get Uri

Get the URI string.

$uriString = $uri->getUri();

Get User Info

Get the user info string.

$userInfo = $uri->getUserInfo();

Resolve Relative Uri

Clone the Uri with a resolved relative URI.

  • $relativeUri is a string representing the relative uri.
$newUri = $uri->resolveRelativeUri($relativeUri);

With Added Query

Clone the Uri with a new query parameter.

  • $key is a string representing the query key.
  • $value is the query value.
$newUri = $uri->withAddedQuery($key, $value);

With Authority

Clone the Uri with a new authority.

  • $authority is a string representing the authority.
$newUri = $uri->withAuthority($authority);

With Fragment

Clone the Uri with a new fragment.

  • $fragment is a string representing the fragment.
$newUri = $uri->withFragment($fragment);

With Host

Clone the Uri with a new host.

  • $host is a string representing the host.
$newUri = $uri->withHost($host);

With Only Query

Clone the Uri with only specific query parameters.

  • $keys is an array containing the query parameters to keep.
$newUri = $uri->withOnlyQuery($keys);

Without Query

Clone the Uri without query parameters.

  • $keys is an array containing the query parameters to remove.
$newUri = $uri->withoutQuery($keys);

With Path

Clone the Uri with a new path.

  • $path is a string representing the path.
$newUri = $uri->withPath($path);

With Port

Clone the Uri with a new port.

  • $port is a number representing the port.
$newUri = $uri->withPort($port);

With Query

Clone the Uri with a new query string.

  • $query is a string representing the query parameters.
$newUri = $uri->withQuery($query);

With Query Params

Clone the Uri with new query parameters.

  • $params is an array containing the query parameters.
$newUri = $uri->withQueryParams($params);

With Scheme

Clone the Uri with a new scheme.

  • $scheme is a string representing the scheme.
$newUri = $uri->withScheme($scheme);

With User Info

Clone the Uri with new user info.

  • $username is a string representing the username.
  • $password is a string representing the password, and will default to null.
$newUri = $uri->withUserInfo($username, $password);