byjg/uri

An implementation of PSR UriInterface

5.0.0 2023-05-18 21:46 UTC

This package is auto-updated.

Last update: 2024-04-16 02:18:26 UTC


README

Scrutinizer Code Quality Build Status Opensource ByJG GitHub source GitHub license GitHub release

An implementation of PSR-7 UriInterface

PSR-7 requires URI compliant to RFC3986. It means the URI output will be always url encoded. The same is valid to create a new instance. The only way to store the plain password is using ->withUserInfo()

For example:

$uri = \ByJG\Util\Uri::getInstanceFromString("http://user:pa&@host");
print((string)$uri); // Will print "http://user:pa%26@host"

$uri = \ByJG\Util\Uri::getInstanceFromString("http://user:pa%26@host");
print((string)$uri); // Will print "http://user:pa%26@host"

$uri = \ByJG\Util\Uri::getInstanceFromString("http://host")
    ->withUserInfo("user", "pa%26");
print((string)$uri); // Will print "http://user:pa%2526@host"

Custom methods

This class is fully compliant with the PSR UriInterface (PSR-7), but it implements some useful extra methods in the interface \ByJG\Util\CustomUriInterface:

  • getUsername()
  • getPassword()
  • getQueryPart($key)
  • withQueryKeyValue($key, $value, $encode = true)

More information about UriInterface: https://github.com/php-fig/http-message/blob/master/src/UriInterface.php

Install

composer require "byjg/uri"

Unit tests

vendor/bin/phpunit

Dependencies

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

Open source ByJG