1 | <?php |
||
8 | class Authority extends AbstractUriPart |
||
9 | { |
||
10 | /** @var UserInfo */ |
||
11 | protected $user_info; |
||
12 | /** @var Host */ |
||
13 | protected $host; |
||
14 | /** @var Port */ |
||
15 | protected $port; |
||
16 | |||
17 | protected $authority_parts = array( |
||
18 | "user_info" => "", |
||
19 | "host" => "", |
||
20 | "port" => null, |
||
21 | ); |
||
22 | |||
23 | protected static $part_pattern; |
||
24 | protected static $valid_pattern; |
||
25 | |||
26 | /** @noinspection PhpMissingParentConstructorInspection */ |
||
27 | /** |
||
28 | * Authority constructor. Accepts a string representing a URI authority component. Construction will throw an |
||
29 | * exception if the authority is not a string. |
||
30 | * |
||
31 | * Construction splits a given authority string into its component objects, UserInfo, Host, and Port, whose |
||
32 | * individual constructors may throw exceptions provided invalid component strings. |
||
33 | * |
||
34 | * Construction accepts strings for UserInfo and Host that have been percent-encoded as well as strings that have |
||
35 | * not been percent-encoded and will encode invalid characters. |
||
36 | * |
||
37 | * Construction with a string that includes both encoded and decoded characters will be assumed to be an encoded |
||
38 | * string, resulting in double-encoding. |
||
39 | * |
||
40 | * authority = [ userinfo "@" ] host [ ":" port ] |
||
41 | * |
||
42 | * @see UserInfo |
||
43 | * @see Host |
||
44 | * @see Port |
||
45 | * @see https://tools.ietf.org/html/rfc3986#appendix-A |
||
46 | * |
||
47 | * @throws \InvalidArgumentException given a non-string |
||
48 | * |
||
49 | * @param string $authority A string representing a URI authority |
||
50 | */ |
||
51 | 110 | public function __construct($authority) |
|
65 | |||
66 | /** |
||
67 | * Returns the authority's UserInfo object |
||
68 | * |
||
69 | * @return UserInfo |
||
70 | */ |
||
71 | 97 | public function getUserInfo() |
|
75 | |||
76 | /** |
||
77 | * Returns the authority's Host object |
||
78 | * |
||
79 | * @return Host |
||
80 | */ |
||
81 | 96 | public function getHost() |
|
85 | |||
86 | /** |
||
87 | * Returns the authority's Port object |
||
88 | * |
||
89 | * @return Port |
||
90 | */ |
||
91 | 97 | public function getPort() |
|
95 | |||
96 | /** |
||
97 | * Returns a string representation of the authority |
||
98 | * |
||
99 | * @return string A string representation of the authority |
||
100 | */ |
||
101 | 33 | public function __toString() |
|
105 | |||
106 | /** |
||
107 | * Returns a string representation of the authority formatted so that it can be compiled into a complete URI string |
||
108 | * per the Uri object's string specification. |
||
109 | * |
||
110 | * If the user info is empty, toUriString returns an authority string with no user info; otherwise, toUriString |
||
111 | * returns the user info suffixed with an at symbol. |
||
112 | * |
||
113 | * If the port is empty, toUriString returns an authority string with no port; otherwise, toUriString returns the |
||
114 | * port prefixed with a colon. |
||
115 | * |
||
116 | * If the authority overall is empty, toUriString returns an empty string; otherwise, toUriString returns the entire |
||
117 | * authority string prefixed with two slashes. |
||
118 | * |
||
119 | * toUriString will also check the port against an optionally-provided scheme; if the port is standard for the given |
||
120 | * scheme, toUriString will not include the port within the authority string. |
||
121 | * |
||
122 | * @see Uri::__toString |
||
123 | * |
||
124 | * @param Scheme|null $scheme [optional] A scheme against which to check if the port is the standard |
||
125 | * |
||
126 | * @return string A string representation of the authority formatted for a complete URI string |
||
127 | */ |
||
128 | 37 | public function toUriString(Scheme $scheme = null) |
|
140 | |||
141 | /** |
||
142 | * Compiles a valid pattern for an authority based upon valid patterns for user info, host, and port. |
||
143 | * |
||
144 | * @return void |
||
145 | */ |
||
146 | 16 | protected static function compileValidPattern() |
|
162 | |||
163 | /** |
||
164 | * Splits URI authority data into user info, host, and port data, returning an array with named keys. |
||
165 | * |
||
166 | * For the host component, it will capture everything within brackets to support ipv6 or match all characters until |
||
167 | * it finds a colon indicating the start of the port component. |
||
168 | * |
||
169 | * @param string $authority The authority part of a URI to be decomposed |
||
170 | * @return mixed[] An array with named keys containing the component parts of the supplied |
||
|
|||
171 | * authority |
||
172 | */ |
||
173 | 98 | protected function explodeAuthority($authority) |
|
191 | } |
||
192 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.