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