An implementation of PSR-7 UriInterface
PSR-7 requires URI compliant with RFC3986. It means the URI output will always be URL encoded. The same is valid for creating a new instance.
The only way to store the plain password is using Uri::withUserInfo()
For example:
$uri = \ByJG\Util\Uri::getInstanceFromString("https://user:pa&@host");
print((string)$uri); // Will print "https://user:pa%26@host"
$uri = \ByJG\Util\Uri::getInstanceFromString("https://user:pa%26@host");
print((string)$uri); // Will print "https://user:pa%26@host"
$uri = \ByJG\Util\Uri::getInstanceFromString("https://host")
->withUserInfo("user", "pa%26");
print((string)$uri); // Will print "https://user:pa%2526@host"
This class fully complies with the PSR UriInterface (PSR-7) and also implements some additional useful methods in the \ByJG\Util\CustomUriInterface
interface:
getUsername()
getPassword()
getQueryPart($key)
withQueryKeyValue($key, $value, $encode = true)
hasQueryKey(string $key): bool;
For more information about UriInterface, visit: 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