-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
UriModifier.php
333 lines (292 loc) · 10.2 KB
/
UriModifier.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
/**
* League.Uri (https://uri.thephpleague.com)
*
* (c) Ignace Nyamagana Butera <nyamsprod@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace League\Uri;
use League\Uri\Contracts\UriInterface;
use League\Uri\Exceptions\SyntaxError;
use Psr\Http\Message\UriInterface as Psr7UriInterface;
use Stringable;
/**
* @deprecated since version 7.0.0
* @codeCoverageIgnore
* @see Modifier
*/
class UriModifier
{
/*********************************
* Query resolution methods
*********************************/
/**
* Add the new query data to the existing URI query.
*/
public static function appendQuery(
Psr7UriInterface|UriInterface $uri,
Stringable|string|null $query
): Psr7UriInterface|UriInterface {
return Modifier::from($uri)->appendQuery($query)->getUri();
}
/**
* Merge a new query with the existing URI query.
*/
public static function mergeQuery(
Psr7UriInterface|UriInterface $uri,
Stringable|string|null $query
): Psr7UriInterface|UriInterface {
return Modifier::from($uri)->mergeQuery($query)->getUri();
}
/**
* Remove query data according to their key name.
*/
public static function removePairs(Psr7UriInterface|UriInterface $uri, string ...$keys): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->removeQueryPairsByKey(...$keys)->getUri();
}
/**
* Remove empty pairs from the URL query component.
*
* A pair is considered empty if it's name is the empty string
* and its value is either the empty string or the null value
*/
public static function removeEmptyPairs(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->removeEmptyQueryPairs()->getUri();
}
/**
* Remove query data according to their key name.
*/
public static function removeParams(Psr7UriInterface|UriInterface $uri, string ...$keys): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->removeQueryParameters(...$keys)->getUri();
}
/**
* Sort the URI query by keys.
*/
public static function sortQuery(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->sortQuery()->getUri();
}
/*********************************
* Host resolution methods
*********************************/
/**
* Add the root label to the URI.
*/
public static function addRootLabel(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->addRootLabel()->getUri();
}
/**
* Append a label or a host to the current URI host.
*
* @throws SyntaxError If the host cannot be appended
*/
public static function appendLabel(Psr7UriInterface|UriInterface $uri, Stringable|string|null $label): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->appendLabel($label)->getUri();
}
/**
* Convert the URI host part to its ascii value.
*/
public static function hostToAscii(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->hostToAscii()->getUri();
}
/**
* Convert the URI host part to its unicode value.
*/
public static function hostToUnicode(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->hostToUnicode()->getUri();
}
/**
* Prepend a label or a host to the current URI host.
*
* @throws SyntaxError If the host cannot be prepended
*/
public static function prependLabel(Psr7UriInterface|UriInterface $uri, Stringable|string|null $label): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->prependLabel($label)->getUri();
}
/**
* Remove host labels according to their offset.
*/
public static function removeLabels(Psr7UriInterface|UriInterface $uri, int ...$keys): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->removeLabels(...$keys)->getUri();
}
/**
* Remove the root label to the URI.
*/
public static function removeRootLabel(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->removeRootLabel()->getUri();
}
/**
* Remove the host zone identifier.
*/
public static function removeZoneId(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->removeZoneId()->getUri();
}
/**
* Replace a label of the current URI host.
*/
public static function replaceLabel(
Psr7UriInterface|UriInterface $uri,
int $offset,
Stringable|string|null $label
): Psr7UriInterface|UriInterface {
return Modifier::from($uri)->replaceLabel($offset, $label)->getUri();
}
/*********************************
* Path resolution methods
*********************************/
/**
* Add a new basepath to the URI path.
*/
public static function addBasePath(Psr7UriInterface|UriInterface $uri, Stringable|string $path): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->addBasePath($path)->getUri();
}
/**
* Add a leading slash to the URI path.
*/
public static function addLeadingSlash(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->addLeadingSlash()->getUri();
}
/**
* Add a trailing slash to the URI path.
*/
public static function addTrailingSlash(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->addTrailingSlash()->getUri();
}
/**
* Append a new segment or a new path to the URI path.
*/
public static function appendSegment(Psr7UriInterface|UriInterface $uri, Stringable|string $segment): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->appendSegment($segment)->getUri();
}
/**
* Convert the Data URI path to its ascii form.
*/
public static function dataPathToAscii(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->dataPathToAscii()->getUri();
}
/**
* Convert the Data URI path to its binary (base64encoded) form.
*/
public static function dataPathToBinary(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->dataPathToBinary()->getUri();
}
/**
* Prepend an new segment or a new path to the URI path.
*/
public static function prependSegment(
Psr7UriInterface|UriInterface $uri,
Stringable|string $segment
): Psr7UriInterface|UriInterface {
return Modifier::from($uri)->prependSegment($segment)->getUri();
}
/**
* Remove a basepath from the URI path.
*/
public static function removeBasePath(
Psr7UriInterface|UriInterface $uri,
Stringable|string $path
): Psr7UriInterface|UriInterface {
return Modifier::from($uri)->removeBasePath($path)->getUri();
}
/**
* Remove dot segments from the URI path.
*/
public static function removeDotSegments(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->removeDotSegments()->getUri();
}
/**
* Remove empty segments from the URI path.
*/
public static function removeEmptySegments(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->removeEmptySegments()->getUri();
}
/**
* Remove the leading slash from the URI path.
*/
public static function removeLeadingSlash(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->removeLeadingSlash()->getUri();
}
/**
* Remove the trailing slash from the URI path.
*/
public static function removeTrailingSlash(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->removeTrailingSlash()->getUri();
}
/**
* Remove path segments from the URI path according to their offsets.
*/
public static function removeSegments(Psr7UriInterface|UriInterface $uri, int ...$keys): Psr7UriInterface|UriInterface
{
return Modifier::from($uri)->removeSegments(...$keys)->getUri();
}
/**
* Replace the URI path basename.
*/
public static function replaceBasename(
Psr7UriInterface|UriInterface $uri,
Stringable|string $basename
): Psr7UriInterface|UriInterface {
return Modifier::from($uri)->replaceBasename($basename)->getUri();
}
/**
* Replace the data URI path parameters.
*/
public static function replaceDataUriParameters(
Psr7UriInterface|UriInterface $uri,
Stringable|string $parameters
): Psr7UriInterface|UriInterface {
return Modifier::from($uri)->replaceDataUriParameters($parameters)->getUri();
}
/**
* Replace the URI path dirname.
*/
public static function replaceDirname(
Psr7UriInterface|UriInterface $uri,
Stringable|string $dirname
): Psr7UriInterface|UriInterface {
return Modifier::from($uri)->replaceDirname($dirname)->getUri();
}
/**
* Replace the URI path basename extension.
*/
public static function replaceExtension(
Psr7UriInterface|UriInterface $uri,
Stringable|string $extension
): Psr7UriInterface|UriInterface {
return Modifier::from($uri)->replaceExtension($extension)->getUri();
}
/**
* Replace a segment from the URI path according its offset.
*/
public static function replaceSegment(
Psr7UriInterface|UriInterface $uri,
int $offset,
Stringable|string $segment
): Psr7UriInterface|UriInterface {
return Modifier::from($uri)->replaceSegment($offset, $segment)->getUri();
}
}