kristos80 / yuri
强化版的 Uris
v1.2.3
2021-06-14 08:01 UTC
Requires
- kristos80/opton: ^1.1
- sabre/uri: ^2.2
README
Yuri
是一个小的实用工具,用于使 URI 有意义,无需反复编写相同的工具方法。
默认情况下,如果省略输入 URI,Yuri
将适用于当前 URL
<?php use Kristos80\Yuri\Yuri; require_once __DIR__ . '/vendor/autoload.php'; $yuri = new Yuri('https://www.dummy.com/path/index.html?q[]=1&q[]=2');
您可以通过使用 asArray()
、asClass()
或 asJsonString()
中的任何一个方法来检查几乎所有返回值
//@see Yuri::asJsonString(bool $prettyPrint = FALSE) echo($yuri->asJsonString(TRUE));
{ "originalUri": "https:\/\/www.dummy.com\/path\/index.html?q[]=1&q[]=2", "normalizedUri": "https:\/\/www.dummy.com\/path\/index.html?q[0]=1&q[1]=2", "normalizedUriWithSlash": "https:\/\/www.dummy.com\/path\/index.html?q[0]=1&q[1]=2", "scheme": "https", "host": "www.dummy.com", "hostWithoutSubdomains": "dummy.com", "tld": "com", "path": "\/path\/index.html", "paths": [ "path", "index.html" ], "query": { "q": [ "1", "2" ] }, "originalQueryString": "q[]=1&q[]=2", "queryString": "q[0]=1&q[1]=2", "port": null, "uid": "6ec78702bb2686046b5102547fbd3d79", "isHttps": true, "isFile": true, "isWww": true }
此外,还有一些额外的工具方法,用于获取有关 path
和 query
的数据,如下所示
//@see Yuri::getQueryVar(string $varNotation, $defaultValue = NULL) //Notation syntax is, also, supported echo $yuri->getQueryVar('q.0','defaultValueIfNotExists');
1
//@see Yuri::getPathByIndex(int $pathIndex = 0) echo $yuri->getPathByIndex();
path
方法
getOriginalUri(): string {} getNormalizedUri(bool $useTrailingSlash = FALSE): string {} isFile(): bool {} isWww(): bool {} getNormalizedUriWithSlash(): string {} getScheme(): ?string {} getHost(bool $removeSubDomains = FALSE): ?string {} getTld(): string {} getPaths(bool $useNullOnEmptyPaths = FALSE): ?array {} getPath(bool $useSlashOnEmptyPath = FALSE): string {} getQuery(): array {} getOriginalQueryString(bool $useQuestionMark = FALSE): string {} getQueryString(bool $useQuestionMark = FALSE): string {} getPort(): ?int {} getUid(): string {} isHttps(): bool {} getPathByIndex(int $pathIndex = 0): ?string {} getQueryVar(string $varNotation, $defaultValue = NULL) {} asArray(): array {} asClass(): \stdClass {} asJsonString(bool $prettyPrint = FALSE): string {}