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"
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
composer require "byjg/uri"
vendor/bin/phpunit
flowchart TD
byjg/uri --> psr/http-message