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 and return its components
21: *
22: * This method replaces and must be used instead of {@see parse_url()} to
23: * mitigate risks arising from the use of multiple URI parsers, which
24: * include inconsistent behaviours and 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: * @param int $component `PHP_URL_SCHEME`, `PHP_URL_HOST`, `PHP_URL_PORT`,
30: * `PHP_URL_USER`, `PHP_URL_PASS`, `PHP_URL_PATH`, `PHP_URL_QUERY` or
31: * `PHP_URL_FRAGMENT` for the given component, or `-1` for all components.
32: * @return (
33: * $component is -1
34: * ? array{scheme?:string,host?:string,port?:int,user?:string,pass?:string,path?:string,query?:string,fragment?:string}|false
35: * : ($component is \PHP_URL_PORT
36: * ? int|null|false
37: * : string|null|false
38: * )
39: * )
40: */
41: public static function parse(string $uri, int $component = -1);
42:
43: /**
44: * Get the components of the URI
45: *
46: * @return array{scheme?:string,host?:string,port?:int,user?:string,pass?:string,path?:string,query?:string,fragment?:string}
47: */
48: public function getComponents(): array;
49:
50: /**
51: * Check if the URI is a relative reference
52: */
53: public function isRelativeReference(): bool;
54:
55: /**
56: * Remove "/./" and "/../" segments from the path of the URI before
57: * optionally applying scheme- and protocol-based normalisation
58: *
59: * It isn't necessary to call this method for scheme, host and
60: * percent-encoded octet normalisation, which are always applied.
61: *
62: * @return static
63: */
64: public function normalise(): UriInterface;
65:
66: /**
67: * Transform a URI reference to a target URI
68: *
69: * The base URI is the one on which this method is called.
70: *
71: * @param PsrUriInterface|Stringable|string $reference
72: * @return static
73: */
74: public function follow($reference): UriInterface;
75:
76: /**
77: * Get the string representation of the URI
78: */
79: public function jsonSerialize(): string;
80: }
81: