talesoft / tale-uri
一个基本的、轻量级的PSR-7和PSR-17兼容URI实现
0.2.0
2019-01-26 12:36 UTC
Requires
- php: >=7.1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- talesoft/tale-dev-tool: dev-master
This package is auto-updated.
Last update: 2024-08-27 01:34:38 UTC
README
Tale Uri
什么是Tale Uri?
这是Psr\Http\Message\UriInterface
和Psr\Http\Message\UriFactoryInterface
的基本和轻量级实现。
它不添加任何额外的方法,它们是直接且无冗余的实现。
在只需URI抽象而无需完整HTTP层的情况下很有用。它对于需要使用Psr\Http\Message\UriInterface
进行测试的库作者也很有用。
安装
composer req talesoft/tale-uri
用法
查看函数文件以查看此库能做什么。
轻松解析和修改URI
use function Tale\uri_parse; $uri = uri_parse('https://google.com/search'); //$uri is a strict implementation of PSR-7's UriInterface echo $uri->getScheme(); //"https" echo $uri->getHost(); "google.com" echo $uri->getPath(); //"/search" echo $uri->withHost("talesoft.codes"); "https://talesoft.codes/search"
为DI容器创建URI工厂
use Psr\Http\Message\UriFactoryInterface; use Tale\UriFactory; $container->add(UriFactory::class); //... $uriFactory = $container->get(UriFactoryInterface::class); $uri = $uriFactory->createUri('https://example.com#test'); echo $uri->getFragment(); //"test"