1 | <?php |
||
10 | class Uri implements UriInterface |
||
11 | { |
||
12 | |||
13 | |||
14 | private $scheme; |
||
15 | |||
16 | public function withScheme($value) |
||
21 | |||
22 | public function getScheme() |
||
26 | |||
27 | private $username; |
||
28 | private $password; |
||
29 | |||
30 | public function withUserInfo($user, $password = null) |
||
36 | |||
37 | public function getUserInfo() |
||
42 | |||
43 | /** |
||
44 | * @return mixed |
||
45 | */ |
||
46 | public function getUsername() |
||
50 | |||
51 | /** |
||
52 | * @return mixed |
||
53 | */ |
||
54 | public function getPassword() |
||
58 | |||
59 | private $host; |
||
60 | |||
61 | public function withHost($value) |
||
66 | |||
67 | public function getHost() |
||
71 | |||
72 | private $port; |
||
73 | |||
74 | /** |
||
75 | * @param int|string|null $value |
||
76 | * @return $this |
||
77 | */ |
||
78 | public function withPort($value) |
||
83 | |||
84 | public function getPort() |
||
88 | |||
89 | private $path; |
||
90 | |||
91 | public function withPath($value) |
||
96 | |||
97 | public function getPath() |
||
101 | |||
102 | private $query = []; |
||
103 | |||
104 | public function withQuery($query) |
||
109 | |||
110 | |||
111 | public function getQuery() |
||
115 | |||
116 | /** |
||
117 | * @param string $key |
||
118 | * @param string|array $value |
||
119 | * @param bool $encode |
||
120 | * @return $this |
||
121 | */ |
||
122 | public function withQueryKeyValue($key, $value, $encode = true) |
||
127 | |||
128 | /** |
||
129 | * Not from UriInterface |
||
130 | * |
||
131 | * @param $key |
||
132 | * @return string |
||
133 | */ |
||
134 | public function getQueryPart($key) |
||
138 | |||
139 | private function getFromArray($array, $key) |
||
147 | |||
148 | private $fragment; |
||
149 | |||
150 | public function getFragment() |
||
154 | |||
155 | public function withFragment($fragment) |
||
160 | |||
161 | public function getAuthority() |
||
162 | { |
||
163 | return |
||
164 | $this->concatSuffix($this->getUserInfo(), "@") |
||
165 | . $this->getHost() |
||
166 | . $this->concatPrefix(':', $this->getPort()); |
||
167 | } |
||
168 | |||
169 | public function __toString() |
||
170 | { |
||
171 | return |
||
172 | $this->concatSuffix($this->getScheme(), ':') |
||
173 | . '//' . $this->getAuthority() |
||
174 | . $this->getPath() |
||
175 | . $this->concatPrefix('?', $this->getQuery()) |
||
176 | . $this->concatPrefix('#', $this->getFragment()); |
||
177 | } |
||
178 | |||
179 | private function concatSuffix($str, $suffix) |
||
180 | { |
||
181 | if (!empty($str)) { |
||
182 | $str = $str . $suffix; |
||
183 | } |
||
184 | return $str; |
||
185 | } |
||
186 | |||
187 | private function concatPrefix($prefix, $str) |
||
188 | { |
||
189 | if (!empty($str)) { |
||
190 | $str = $prefix . $str; |
||
191 | } |
||
192 | return $str; |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * @param string $uri |
||
197 | */ |
||
198 | public function __construct($uri = null) |
||
212 | } |
||
213 |