Skip to main content

Uri class

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:


composer require "byjg/uri"

Unit tests



Open source ByJG