1 | <?php |
||
31 | class Formatter |
||
32 | { |
||
33 | use PathFormatterTrait; |
||
34 | |||
35 | /** |
||
36 | * Constants for host formatting |
||
37 | */ |
||
38 | const HOST_AS_UNICODE = 1; |
||
39 | const HOST_AS_ASCII = 2; |
||
40 | |||
41 | /** |
||
42 | * host encoding property |
||
43 | * |
||
44 | * @var int |
||
45 | */ |
||
46 | protected $hostEncoding = self::HOST_AS_UNICODE; |
||
47 | |||
48 | /** |
||
49 | * query encoding property |
||
50 | * |
||
51 | * @var int |
||
52 | */ |
||
53 | protected $queryEncoding = PHP_QUERY_RFC3986; |
||
54 | |||
55 | /** |
||
56 | * URI Parser object |
||
57 | * |
||
58 | * @var UriParser |
||
59 | */ |
||
60 | protected $uriParser; |
||
61 | |||
62 | /** |
||
63 | * Query Parser object |
||
64 | * |
||
65 | * @var QueryParser |
||
66 | */ |
||
67 | protected $queryParser; |
||
68 | |||
69 | /** |
||
70 | * query separator property |
||
71 | * |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $querySeparator = '&'; |
||
75 | |||
76 | 28 | /** |
|
77 | * Should the query component be preserved |
||
78 | 28 | * |
|
79 | 28 | * @var bool |
|
80 | 28 | */ |
|
81 | protected $preserveQuery = false; |
||
82 | |||
83 | /** |
||
84 | * Should the fragment component string be preserved |
||
85 | * |
||
86 | * @var bool |
||
87 | 14 | */ |
|
88 | protected $preserveFragment = false; |
||
89 | 14 | ||
90 | 2 | /** |
|
91 | * New Instance |
||
92 | 12 | */ |
|
93 | 12 | public function __construct() |
|
98 | |||
99 | /** |
||
100 | 2 | * Host encoding setter |
|
101 | * |
||
102 | 2 | * @param int $encode a predefined constant value |
|
103 | */ |
||
104 | public function setHostEncoding($encode) |
||
111 | |||
112 | 6 | /** |
|
113 | 2 | * Host encoding getter |
|
114 | * |
||
115 | 4 | * @return int |
|
116 | 4 | */ |
|
117 | public function getHostEncoding() |
||
121 | |||
122 | /** |
||
123 | 2 | * Query encoding setter |
|
124 | * |
||
125 | 2 | * @param int $encode a predefined constant value |
|
126 | */ |
||
127 | public function setQueryEncoding($encode) |
||
134 | |||
135 | 10 | /** |
|
136 | * Query encoding getter |
||
137 | 10 | * |
|
138 | 10 | * @return int |
|
139 | */ |
||
140 | public function getQueryEncoding() |
||
144 | |||
145 | 2 | /** |
|
146 | * Query separator setter |
||
147 | 2 | * |
|
148 | * @param string $separator |
||
149 | */ |
||
150 | public function setQuerySeparator($separator) |
||
156 | |||
157 | 24 | /** |
|
158 | * Query separator getter |
||
159 | 24 | * |
|
160 | 12 | * @return string |
|
161 | */ |
||
162 | public function getQuerySeparator() |
||
166 | |||
167 | 2 | /** |
|
168 | * Whether we should preserve the Query component |
||
169 | 2 | * regardless of its value. |
|
170 | * |
||
171 | * If set to true the query delimiter will be appended |
||
172 | * to the URI regardless of the query string value |
||
173 | * |
||
174 | * @param bool $status |
||
175 | */ |
||
176 | public function preserveQuery($status) |
||
180 | |||
181 | 22 | /** |
|
182 | 16 | * Whether we should preserve the Fragment component |
|
183 | * regardless of its value. |
||
184 | * |
||
185 | 6 | * If set to true the query delimiter will be appended |
|
186 | 4 | * to the URI regardless of the query string value |
|
187 | * |
||
188 | * @param bool $status |
||
189 | 2 | */ |
|
190 | public function preserveFragment($status) |
||
194 | |||
195 | /** |
||
196 | * Format an object according to the formatter properties |
||
197 | * |
||
198 | * @param UriInterface|Interfaces\Uri|Interfaces\Components\UriPart $input |
||
199 | 10 | * |
|
200 | * @return string |
||
201 | 10 | */ |
|
202 | 6 | public function format($input) |
|
216 | |||
217 | 10 | /** |
|
218 | 10 | * Format an object according to the formatter properties |
|
219 | 8 | * |
|
220 | 8 | * @param UriInterface|Interfaces\Uri|Interfaces\Components\UriPart $input |
|
221 | * |
||
222 | 10 | * @return string |
|
223 | 10 | */ |
|
224 | 8 | public function __invoke($input) |
|
228 | 10 | ||
229 | 8 | /** |
|
230 | 8 | * Format a UriPart implemented object according to the Formatter properties |
|
231 | * |
||
232 | 10 | * @param UriPart $part |
|
233 | * |
||
234 | 10 | * @return string |
|
235 | */ |
||
236 | protected function formatUriPart(UriPart $part) |
||
248 | |||
249 | /** |
||
250 | 6 | * Format a HostInterface according to the Formatter properties |
|
251 | 6 | * |
|
252 | 6 | * @param HostInterface $host |
|
253 | 2 | * |
|
254 | 2 | * @return string |
|
255 | */ |
||
256 | protected function formatHost(HostInterface $host) |
||
264 | |||
265 | /** |
||
266 | * Format a Interfaces\Schemes\Uri according to the Formatter properties |
||
267 | * |
||
268 | * @param Uri|UriInterface $uri |
||
269 | * |
||
270 | * @return string |
||
271 | */ |
||
272 | protected function formatUri($uri) |
||
286 | |||
287 | /** |
||
288 | * Format a URI authority according to the Formatter properties |
||
289 | * |
||
290 | * @param UriInterface|Uri $uri |
||
291 | * |
||
292 | * @return string |
||
293 | */ |
||
294 | protected function formatAuthority($uri) |
||
311 | |||
312 | /** |
||
313 | * Format a URI Query component according to the Formatter properties |
||
314 | * |
||
315 | * @param UriInterface|Uri $uri |
||
316 | * |
||
317 | * @return string |
||
318 | */ |
||
319 | protected function formatQuery($uri) |
||
328 | |||
329 | /** |
||
330 | * Format a URI Fragment component according to the Formatter properties |
||
331 | * |
||
332 | * @param UriInterface|Uri $uri |
||
333 | * |
||
334 | * @return string |
||
335 | */ |
||
336 | protected function formatFragment($uri) |
||
345 | } |
||
346 |