fyre / uri
A URI library.
Installs: 315
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
pkg:composer/fyre/uri
Requires
- fyre/macro: ^2.0
- psr/http-message: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^12
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
$uriStringis 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.
$segmentis 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.
$relativeUriis a string representing the relative uri.
$newUri = $uri->resolveRelativeUri($relativeUri);
With Added Query
Clone the Uri with a new query parameter.
$keyis a string representing the query key.$valueis the query value.
$newUri = $uri->withAddedQuery($key, $value);
With Authority
Clone the Uri with a new authority.
$authorityis a string representing the authority.
$newUri = $uri->withAuthority($authority);
With Fragment
Clone the Uri with a new fragment.
$fragmentis a string representing the fragment.
$newUri = $uri->withFragment($fragment);
With Host
Clone the Uri with a new host.
$hostis a string representing the host.
$newUri = $uri->withHost($host);
With Only Query
Clone the Uri with only specific query parameters.
$keysis an array containing the query parameters to keep.
$newUri = $uri->withOnlyQuery($keys);
Without Query
Clone the Uri without query parameters.
$keysis an array containing the query parameters to remove.
$newUri = $uri->withoutQuery($keys);
With Path
Clone the Uri with a new path.
$pathis a string representing the path.
$newUri = $uri->withPath($path);
With Port
Clone the Uri with a new port.
$portis a number representing the port.
$newUri = $uri->withPort($port);
With Query
Clone the Uri with a new query string.
$queryis a string representing the query parameters.
$newUri = $uri->withQuery($query);
With Query Params
Clone the Uri with new query parameters.
$paramsis an array containing the query parameters.
$newUri = $uri->withQueryParams($params);
With Scheme
Clone the Uri with a new scheme.
$schemeis a string representing the scheme.
$newUri = $uri->withScheme($scheme);
With User Info
Clone the Uri with new user info.
$usernameis a string representing the username.$passwordis a string representing the password, and will default to null.
$newUri = $uri->withUserInfo($username, $password);