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%[email protected]"

$uri = \ByJG\Util\Uri::getInstanceFromString("http://user:pa%[email protected]");
print((string)$uri); // Will print "http://user:pa%[email protected]"

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

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

Open source ByJG