byjg / uri
An implementation of PSR-7 Uri Interface
Fund package maintenance!
byjg
Installs: 437 962
Dependents: 3
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 3
Open Issues: 0
Type:project
Requires
- php: >=8.1 <8.4
- psr/http-message: ^1.0|^1.1|^2.0
Requires (Dev)
- phpunit/phpunit: ^9.6
- vimeo/psalm: ^5.0
Provides
README
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"
Custom methods
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
Install
composer require "byjg/uri"
Unit tests
vendor/bin/phpunit