13
13
14
14
15
15
/**
16
- * URI Syntax (RFC 3986) .
16
+ * Mutable representation of a URL .
17
17
*
18
18
* <pre>
19
19
* scheme user password host port basePath relativeUrl
25
25
* authority path query fragment
26
26
* </pre>
27
27
*
28
- * - authority: [user[:password]@]host[:port]
29
- * - hostUrl: http://user:[email protected] :8042
30
- * - basePath: /en/ (everything before relative URI not including the script name)
31
- * - baseUrl: http://user:[email protected] :8042/en/
32
- * - relativeUrl: manual.php
33
- *
34
28
* @property string $scheme
35
29
* @property string $user
36
30
* @property string $password
@@ -56,8 +50,6 @@ class Url implements \JsonSerializable
56
50
'http ' => 80 ,
57
51
'https ' => 443 ,
58
52
'ftp ' => 21 ,
59
- 'news ' => 119 ,
60
- 'nntp ' => 119 ,
61
53
];
62
54
63
55
/** @var string */
@@ -116,80 +108,64 @@ public function __construct($url = null)
116
108
117
109
118
110
/**
119
- * Sets the scheme part of URI.
120
111
* @return static
121
112
*/
122
- public function setScheme (string $ value )
113
+ public function setScheme (string $ scheme )
123
114
{
124
- $ this ->scheme = $ value ;
115
+ $ this ->scheme = $ scheme ;
125
116
return $ this ;
126
117
}
127
118
128
119
129
- /**
130
- * Returns the scheme part of URI.
131
- */
132
120
public function getScheme (): string
133
121
{
134
122
return $ this ->scheme ;
135
123
}
136
124
137
125
138
126
/**
139
- * Sets the user name part of URI.
140
127
* @return static
141
128
*/
142
- public function setUser (string $ value )
129
+ public function setUser (string $ user )
143
130
{
144
- $ this ->user = $ value ;
131
+ $ this ->user = $ user ;
145
132
return $ this ;
146
133
}
147
134
148
135
149
- /**
150
- * Returns the user name part of URI.
151
- */
152
136
public function getUser (): string
153
137
{
154
138
return $ this ->user ;
155
139
}
156
140
157
141
158
142
/**
159
- * Sets the password part of URI.
160
143
* @return static
161
144
*/
162
- public function setPassword (string $ value )
145
+ public function setPassword (string $ password )
163
146
{
164
- $ this ->password = $ value ;
147
+ $ this ->password = $ password ;
165
148
return $ this ;
166
149
}
167
150
168
151
169
- /**
170
- * Returns the password part of URI.
171
- */
172
152
public function getPassword (): string
173
153
{
174
154
return $ this ->password ;
175
155
}
176
156
177
157
178
158
/**
179
- * Sets the host part of URI.
180
159
* @return static
181
160
*/
182
- public function setHost (string $ value )
161
+ public function setHost (string $ host )
183
162
{
184
- $ this ->host = $ value ;
163
+ $ this ->host = $ host ;
185
164
$ this ->setPath ($ this ->path );
186
165
return $ this ;
187
166
}
188
167
189
168
190
- /**
191
- * Returns the host part of URI.
192
- */
193
169
public function getHost (): string
194
170
{
195
171
return $ this ->host ;
@@ -208,77 +184,64 @@ public function getDomain(int $level = 2): string
208
184
209
185
210
186
/**
211
- * Sets the port part of URI.
212
187
* @return static
213
188
*/
214
- public function setPort (int $ value )
189
+ public function setPort (int $ port )
215
190
{
216
- $ this ->port = $ value ;
191
+ $ this ->port = $ port ;
217
192
return $ this ;
218
193
}
219
194
220
195
221
- /**
222
- * Returns the port part of URI.
223
- */
224
196
public function getPort (): ?int
225
197
{
226
198
return $ this ->port ?: (self ::$ defaultPorts [$ this ->scheme ] ?? null );
227
199
}
228
200
229
201
230
202
/**
231
- * Sets the path part of URI.
232
203
* @return static
233
204
*/
234
- public function setPath (string $ value )
205
+ public function setPath (string $ path )
235
206
{
236
- $ this ->path = $ value ;
207
+ $ this ->path = $ path ;
237
208
if ($ this ->host && substr ($ this ->path , 0 , 1 ) !== '/ ' ) {
238
209
$ this ->path = '/ ' . $ this ->path ;
239
210
}
240
211
return $ this ;
241
212
}
242
213
243
214
244
- /**
245
- * Returns the path part of URI.
246
- */
247
215
public function getPath (): string
248
216
{
249
217
return $ this ->path ;
250
218
}
251
219
252
220
253
221
/**
254
- * Sets the query part of URI.
255
222
* @param string|array $value
256
223
* @return static
257
224
*/
258
- public function setQuery ($ value )
225
+ public function setQuery ($ query )
259
226
{
260
- $ this ->query = is_array ($ value ) ? $ value : self ::parseQuery ($ value );
227
+ $ this ->query = is_array ($ query ) ? $ query : self ::parseQuery ($ query );
261
228
return $ this ;
262
229
}
263
230
264
231
265
232
/**
266
- * Appends the query part of URI.
267
233
* @param string|array $value
268
234
* @return static
269
235
*/
270
- public function appendQuery ($ value )
236
+ public function appendQuery ($ query )
271
237
{
272
- $ this ->query = is_array ($ value )
273
- ? $ value + $ this ->query
274
- : self ::parseQuery ($ this ->getQuery () . '& ' . $ value );
238
+ $ this ->query = is_array ($ query )
239
+ ? $ query + $ this ->query
240
+ : self ::parseQuery ($ this ->getQuery () . '& ' . $ query );
275
241
return $ this ;
276
242
}
277
243
278
244
279
- /**
280
- * Returns the query part of URI.
281
- */
282
245
public function getQuery (): string
283
246
{
284
247
return http_build_query ($ this ->query , '' , '& ' , PHP_QUERY_RFC3986 );
@@ -315,28 +278,21 @@ public function setQueryParameter(string $name, $value)
315
278
316
279
317
280
/**
318
- * Sets the fragment part of URI.
319
281
* @return static
320
282
*/
321
- public function setFragment (string $ value )
283
+ public function setFragment (string $ fragment )
322
284
{
323
- $ this ->fragment = $ value ;
285
+ $ this ->fragment = $ fragment ;
324
286
return $ this ;
325
287
}
326
288
327
289
328
- /**
329
- * Returns the fragment part of URI.
330
- */
331
290
public function getFragment (): string
332
291
{
333
292
return $ this ->fragment ;
334
293
}
335
294
336
295
337
- /**
338
- * Returns the entire URI including query string and fragment.
339
- */
340
296
public function getAbsoluteUrl (): string
341
297
{
342
298
return $ this ->getHostUrl () . $ this ->path
@@ -372,28 +328,19 @@ public function getHostUrl(): string
372
328
}
373
329
374
330
375
- /**
376
- * Returns the base-path.
377
- */
378
331
public function getBasePath (): string
379
332
{
380
333
$ pos = strrpos ($ this ->path , '/ ' );
381
334
return $ pos === false ? '' : substr ($ this ->path , 0 , $ pos + 1 );
382
335
}
383
336
384
337
385
- /**
386
- * Returns the base-URI.
387
- */
388
338
public function getBaseUrl (): string
389
339
{
390
340
return $ this ->getHostUrl () . $ this ->getBasePath ();
391
341
}
392
342
393
343
394
- /**
395
- * Returns the relative-URI.
396
- */
397
344
public function getRelativeUrl (): string
398
345
{
399
346
return substr ($ this ->getAbsoluteUrl (), strlen ($ this ->getBaseUrl ()));
0 commit comments