1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Contract\Http; |
4: | |
5: | use Psr\Http\Message\UriInterface as PsrUriInterface; |
6: | use Salient\Contract\Core\Immutable; |
7: | use JsonSerializable; |
8: | use Stringable; |
9: | |
10: | /** |
11: | * @api |
12: | */ |
13: | interface UriInterface extends |
14: | PsrUriInterface, |
15: | Stringable, |
16: | JsonSerializable, |
17: | Immutable |
18: | { |
19: | /** |
20: | * Parse a URI into its components |
21: | * |
22: | * This method should be used instead of {@see parse_url()} in scenarios |
23: | * where using multiple URI parsers could introduce inconsistent behaviour |
24: | * or security vulnerabilities. |
25: | * |
26: | * @link https://claroty.com/team82/research/white-papers/exploiting-url-parsing-confusion |
27: | * @link https://daniel.haxx.se/blog/2022/01/10/dont-mix-url-parsers/ |
28: | * |
29: | * @template T of \PHP_URL_SCHEME|\PHP_URL_HOST|\PHP_URL_PORT|\PHP_URL_USER|\PHP_URL_PASS|\PHP_URL_PATH|\PHP_URL_QUERY|\PHP_URL_FRAGMENT|-1|null |
30: | * |
31: | * @param T $component |
32: | * @return ( |
33: | * T is -1|null |
34: | * ? array{scheme?:string,host?:string,port?:int,user?:string,pass?:string,path?:string,query?:string,fragment?:string}|false |
35: | * : (T is \PHP_URL_PORT |
36: | * ? int|null|false |
37: | * : string|null|false |
38: | * ) |
39: | * ) |
40: | */ |
41: | public static function parse(string $uri, ?int $component = null); |
42: | |
43: | /** |
44: | * Get the URI as an array of components |
45: | * |
46: | * Components not present in the URI are not returned. |
47: | * |
48: | * @return array{scheme?:string,host?:string,port?:int,user?:string,pass?:string,path?:string,query?:string,fragment?:string} |
49: | */ |
50: | public function toParts(): array; |
51: | |
52: | /** |
53: | * Check if the URI is a relative reference |
54: | */ |
55: | public function isReference(): bool; |
56: | |
57: | /** |
58: | * Get a normalised instance |
59: | * |
60: | * Removes "/./" and "/../" segments from the path. \[RFC3986]-compliant |
61: | * scheme- and protocol-based normalisation may also be performed. |
62: | * |
63: | * Scheme, host and percent-encoded octets in the URI are not normalised by |
64: | * this method because they are always normalised. |
65: | * |
66: | * @return static |
67: | */ |
68: | public function normalise(): UriInterface; |
69: | |
70: | /** |
71: | * Resolve a URI reference to a target URI with the instance as its base URI |
72: | * |
73: | * Implements \[RFC3986] Section 5.2.2 ("Transform References"). |
74: | * |
75: | * @param PsrUriInterface|Stringable|string $reference |
76: | * @return static |
77: | */ |
78: | public function follow($reference): UriInterface; |
79: | |
80: | /** |
81: | * Get the string representation of the URI |
82: | */ |
83: | public function jsonSerialize(): string; |
84: | } |
85: |