1 | <?php |
||
32 | class Formatter |
||
33 | { |
||
34 | use UriBuilderTrait; |
||
35 | |||
36 | const HOST_AS_UNICODE = 1; |
||
37 | |||
38 | const HOST_AS_ASCII = 2; |
||
39 | |||
40 | /** |
||
41 | * host encoding property |
||
42 | * |
||
43 | * @var int |
||
44 | */ |
||
45 | protected $hostEncoding = self::HOST_AS_UNICODE; |
||
46 | |||
47 | /** |
||
48 | * query encoding property |
||
49 | * |
||
50 | * @var int |
||
51 | */ |
||
52 | protected $queryEncoding = PHP_QUERY_RFC3986; |
||
53 | |||
54 | /** |
||
55 | * Query Parser object |
||
56 | * |
||
57 | * @var QueryParser |
||
58 | */ |
||
59 | protected $queryParser; |
||
60 | |||
61 | /** |
||
62 | * query separator property |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $querySeparator = '&'; |
||
67 | |||
68 | /** |
||
69 | * Should the query component be preserved |
||
70 | * |
||
71 | * @var bool |
||
72 | */ |
||
73 | protected $preserveQuery = false; |
||
74 | |||
75 | /** |
||
76 | * Should the fragment component string be preserved |
||
77 | * |
||
78 | * @var bool |
||
79 | */ |
||
80 | protected $preserveFragment = false; |
||
81 | |||
82 | /** |
||
83 | * New Instance |
||
84 | */ |
||
85 | 48 | public function __construct() |
|
89 | |||
90 | /** |
||
91 | * Host encoding setter |
||
92 | * |
||
93 | * @param int $encode a predefined constant value |
||
94 | */ |
||
95 | 21 | public function setHostEncoding($encode) |
|
102 | |||
103 | /** |
||
104 | * Host encoding getter |
||
105 | * |
||
106 | * DEPRECATION WARNING! This method will be removed in the next major point release |
||
107 | * |
||
108 | * @deprecated deprecated since version 4.1 |
||
109 | * |
||
110 | * @return int |
||
111 | */ |
||
112 | public function getHostEncoding() |
||
116 | |||
117 | /** |
||
118 | * Query encoding setter |
||
119 | * |
||
120 | * @param int $encode a predefined constant value |
||
121 | */ |
||
122 | 9 | public function setQueryEncoding($encode) |
|
129 | |||
130 | /** |
||
131 | * Query encoding getter |
||
132 | * |
||
133 | * DEPRECATION WARNING! This method will be removed in the next major point release |
||
134 | * |
||
135 | * @deprecated deprecated since version 4.1 |
||
136 | * |
||
137 | * @return int |
||
138 | */ |
||
139 | public function getQueryEncoding() |
||
143 | |||
144 | /** |
||
145 | * Query separator setter |
||
146 | * |
||
147 | * @param string $separator |
||
148 | */ |
||
149 | 15 | public function setQuerySeparator($separator) |
|
155 | |||
156 | /** |
||
157 | * Query separator getter |
||
158 | * |
||
159 | * DEPRECATION WARNING! This method will be removed in the next major point release |
||
160 | * |
||
161 | * @deprecated deprecated since version 4.1 |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | public function getQuerySeparator() |
||
169 | |||
170 | /** |
||
171 | * Whether we should preserve the Query component |
||
172 | * regardless of its value. |
||
173 | * |
||
174 | * If set to true the query delimiter will be appended |
||
175 | * to the URI regardless of the query string value |
||
176 | * |
||
177 | * @param bool $status |
||
178 | */ |
||
179 | 3 | public function preserveQuery($status) |
|
183 | |||
184 | /** |
||
185 | * Whether we should preserve the Fragment component |
||
186 | * regardless of its value. |
||
187 | * |
||
188 | * If set to true the fragment delimiter will be appended |
||
189 | * to the URI regardless of the query string value |
||
190 | * |
||
191 | * @param bool $status |
||
192 | */ |
||
193 | 3 | public function preserveFragment($status) |
|
197 | |||
198 | /** |
||
199 | * Format an object |
||
200 | * |
||
201 | * @see Formatter::format |
||
202 | * |
||
203 | * @param UriPart|Uri|UriInterface $input |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | 39 | public function __invoke($input) |
|
211 | |||
212 | /** |
||
213 | * Format an object |
||
214 | * |
||
215 | * Format an object according to the formatter properties. |
||
216 | * The object must implement one of the following interface: |
||
217 | * <ul> |
||
218 | * <li>League\Uri\Interfaces\Uri |
||
219 | * <li>League\Uri\Interfaces\UriPart |
||
220 | * <li>Psr\Http\Message\UriInterface |
||
221 | * </ul> |
||
222 | * |
||
223 | * @param UriPart|Uri|UriInterface $input |
||
224 | * |
||
225 | * @return string |
||
226 | */ |
||
227 | 42 | public function format($input) |
|
241 | |||
242 | /** |
||
243 | * Format a UriPart implemented object according to the Formatter properties |
||
244 | * |
||
245 | * @param UriPart $part |
||
246 | * |
||
247 | * @return string |
||
248 | */ |
||
249 | 39 | protected function formatUriPart(UriPart $part) |
|
261 | |||
262 | /** |
||
263 | * Format a Host according to the Formatter properties |
||
264 | * |
||
265 | * @param HostInterface $host |
||
266 | * |
||
267 | * @return string |
||
268 | */ |
||
269 | 21 | protected function formatHost(HostInterface $host) |
|
277 | |||
278 | /** |
||
279 | * Format an Uri according to the Formatter properties |
||
280 | * |
||
281 | * @param Uri|UriInterface $uri |
||
282 | * |
||
283 | * @return string |
||
284 | */ |
||
285 | 21 | protected function formatUri($uri) |
|
299 | |||
300 | /** |
||
301 | * Format a URI authority according to the Formatter properties |
||
302 | * |
||
303 | * @param Uri|UriInterface $uri |
||
304 | * |
||
305 | * @return string |
||
306 | */ |
||
307 | 21 | protected function formatAuthority($uri) |
|
326 | |||
327 | /** |
||
328 | * Format a URI port component according to the Formatter properties |
||
329 | * |
||
330 | * @param null|int $port |
||
331 | * |
||
332 | * @return string |
||
333 | */ |
||
334 | 15 | protected function formatPort($port) |
|
342 | |||
343 | /** |
||
344 | * Format a URI Query component according to the Formatter properties |
||
345 | * |
||
346 | * @param Uri|UriInterface $uri |
||
347 | * |
||
348 | * @return string |
||
349 | */ |
||
350 | 21 | protected function formatQuery($uri) |
|
359 | |||
360 | /** |
||
361 | * Format a URI Fragment component according to the Formatter properties |
||
362 | * |
||
363 | * @param Uri|UriInterface $uri |
||
364 | * |
||
365 | * @return string |
||
366 | */ |
||
367 | 21 | protected function formatFragment($uri) |
|
376 | } |
||
377 |