byjg / uri
PSR UriInterface的实现
5.0.1
2024-06-09 18:36 UTC
Requires
- php: >=7.4
- psr/http-message: ^1.0|^2.0
Requires (Dev)
- phpunit/phpunit: 5.7.*|7.4.*|^9.5
Provides
README
PSR-7 UriInterface的实现
PSR-7要求URI符合RFC3986规范。这意味着URI输出将始终是url编码。同样适用于创建新实例。存储明文密码的唯一方法是使用 ->withUserInfo()
例如
$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"
自定义方法
此类完全符合PSR UriInterface (PSR-7)规范,但它还在接口 \ByJG\Util\CustomUriInterface中实现了一些有用的额外方法
- getUsername()
- getPassword()
- getQueryPart($key)
- withQueryKeyValue($key, $value, $encode = true)
关于UriInterface的更多信息:https://github.com/php-fig/http-message/blob/master/src/UriInterface.php
安装
composer require "byjg/uri"
单元测试
vendor/bin/phpunit