C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$RTQJQKE\vendor\slim\psr7\src\Uri.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
<?php

/**
 * Slim Framework (https://slimframework.com)
 *
 * @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License)
 */

declare(strict_types=1);

namespace 
Slim\Psr7;

use 
InvalidArgumentException;
use 
Psr\Http\Message\UriInterface;

use function 
filter_var;
use function 
is_integer;
use function 
is_null;
use function 
is_object;
use function 
is_string;
use function 
ltrim;
use function 
method_exists;
use function 
preg_replace_callback;
use function 
rawurlencode;
use function 
str_replace;
use function 
strtolower;

use const 
FILTER_FLAG_IPV6;
use const 
FILTER_VALIDATE_IP;

class 
Uri implements UriInterface
{
    public const 
SUPPORTED_SCHEMES = [
        
'' => null,
        
'http' => 80,
        
'https' => 443
    
];

    
/**
     * Uri scheme (without "://" suffix)
     *
     * @var string
     */
    
protected $scheme '';

    
/**
     * @var string
     */
    
protected $user '';

    
/**
     * @var string
     */
    
protected $password '';

    
/**
     * @var string
     */
    
protected $host '';

    
/**
     * @var null|int
     */
    
protected $port;

    
/**
     * @var string
     */
    
protected $path '';

    
/**
     * Uri query string (without "?" prefix)
     *
     * @var string
     */
    
protected $query '';

    
/**
     * Uri fragment string (without "#" prefix)
     *
     * @var string
     */
    
protected $fragment '';

    
/**
     * @param string $scheme   Uri scheme.
     * @param string $host     Uri host.
     * @param int    $port     Uri port number.
     * @param string $path     Uri path.
     * @param string $query    Uri query string.
     * @param string $fragment Uri fragment.
     * @param string $user     Uri user.
     * @param string $password Uri password.
     */
    
public function __construct(
        
string $scheme,
        
string $host,
        ?
int $port null,
        
string $path '/',
        
string $query '',
        
string $fragment '',
        
string $user '',
        
string $password ''
    
) {
        
$this->scheme $this->filterScheme($scheme);
        
$this->host $this->filterHost($host);
        
$this->port $this->filterPort($port);
        
$this->path $this->filterPath($path);
        
$this->query $this->filterQuery($query);
        
$this->fragment $this->filterFragment($fragment);
        
$this->user $user;
        
$this->password $password;
    }

    
/**
     * {@inheritdoc}
     */
    
public function getScheme(): string
    
{
        return 
$this->scheme;
    }

    
/**
     * {@inheritdoc}
     */
    
public function withScheme($scheme)
    {
        
$scheme $this->filterScheme($scheme);
        
$clone = clone $this;
        
$clone->scheme $scheme;

        return 
$clone;
    }

    
/**
     * Filter Uri scheme.
     *
     * @param  mixed $scheme Raw Uri scheme.
     *
     * @return string
     *
     * @throws InvalidArgumentException If the Uri scheme is not a string.
     * @throws InvalidArgumentException If Uri scheme is not exists in SUPPORTED_SCHEMES
     */
    
protected function filterScheme($scheme): string
    
{
        if (!
is_string($scheme)) {
            throw new 
InvalidArgumentException('Uri scheme must be a string.');
        }

        
$scheme str_replace('://'''strtolower($scheme));
        if (!
key_exists($schemeself::SUPPORTED_SCHEMES)) {
            throw new 
InvalidArgumentException(
                
'Uri scheme must be one of: "' implode('", "'array_keys(static::SUPPORTED_SCHEMES)) . '"'
            
);
        }

        return 
$scheme;
    }

    
/**
     * {@inheritdoc}
     */
    
public function getAuthority(): string
    
{
        
$userInfo $this->getUserInfo();
        
$host $this->getHost();
        
$port $this->getPort();

        return (
$userInfo !== '' $userInfo '@' '') . $host . ($port !== null ':' $port '');
    }

    
/**
     * {@inheritdoc}
     */
    
public function getUserInfo(): string
    
{
        
$info $this->user;

        if (isset(
$this->password) && $this->password !== '') {
            
$info .= ':' $this->password;
        }

        return 
$info;
    }

    
/**
     * {@inheritdoc}
     */
    
public function withUserInfo($user$password null)
    {
        
$clone = clone $this;
        
$clone->user $this->filterUserInfo($user);

        if (
$clone->user !== '') {
            
$clone->password $this->filterUserInfo($password);
        } else {
            
$clone->password '';
        }

        return 
$clone;
    }

    
/**
     * Filters the user info string.
     *
     * Returns the percent-encoded query string.
     *
     * @param string|null $info The raw uri query string.
     *
     * @return string
     */
    
protected function filterUserInfo(?string $info null): string
    
{
        if (!
is_string($info)) {
            return 
'';
        }

        
$match =  preg_replace_callback(
            
'/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=]+|%(?![A-Fa-f0-9]{2}))/u',
            function (
$match) {
                return 
rawurlencode($match[0]);
            },
            
$info
        
);

        return 
is_string($match) ? $match '';
    }

    
/**
     * {@inheritdoc}
     */
    
public function getHost(): string
    
{
        return 
$this->host;
    }

    
/**
     * {@inheritdoc}
     */
    
public function withHost($host)
    {
        
$clone = clone $this;
        
$clone->host $this->filterHost($host);

        return 
$clone;
    }

    
/**
     * Filter Uri host.
     *
     * If the supplied host is an IPv6 address, then it is converted to a reference
     * as per RFC 2373.
     *
     * @param  mixed $host The host to filter.
     *
     * @return string
     *
     * @throws InvalidArgumentException for invalid host names.
     */
    
protected function filterHost($host): string
    
{
        if (
is_object($host) && method_exists($host'__toString')) {
            
$host = (string) $host;
        }

        if (!
is_string($host)) {
            throw new 
InvalidArgumentException('Uri host must be a string');
        }

        if (
filter_var($hostFILTER_VALIDATE_IPFILTER_FLAG_IPV6)) {
            
$host '[' $host ']';
        }

        return 
strtolower($host);
    }

    
/**
     * {@inheritdoc}
     */
    
public function getPort(): ?int
    
{
        return 
$this->port && !$this->hasStandardPort() ? $this->port null;
    }

    
/**
     * {@inheritdoc}
     */
    
public function withPort($port)
    {
        
$port $this->filterPort($port);
        
$clone = clone $this;
        
$clone->port $port;

        return 
$clone;
    }

    
/**
     * Does this Uri use a standard port?
     *
     * @return bool
     */
    
protected function hasStandardPort(): bool
    
{
        return static::
SUPPORTED_SCHEMES[$this->scheme] === $this->port;
    }

    
/**
     * Filter Uri port.
     *
     * @param  null|int $port The Uri port number.
     *
     * @return null|int
     *
     * @throws InvalidArgumentException If the port is invalid.
     */
    
protected function filterPort($port): ?int
    
{
        if (
is_null($port) || (is_integer($port) && ($port >= && $port <= 65535))) {
            return 
$port;
        }

        throw new 
InvalidArgumentException('Uri port must be null or an integer between 1 and 65535 (inclusive)');
    }

    
/**
     * {@inheritdoc}
     */
    
public function getPath(): string
    
{
        return 
$this->path;
    }

    
/**
     * {@inheritdoc}
     */
    
public function withPath($path)
    {
        if (!
is_string($path)) {
            throw new 
InvalidArgumentException('Uri path must be a string');
        }

        
$clone = clone $this;
        
$clone->path $this->filterPath($path);

        return 
$clone;
    }

    
/**
     * Filter Uri path.
     *
     * This method percent-encodes all reserved characters in the provided path string.
     * This method will NOT double-encode characters that are already percent-encoded.
     *
     * @param  string $path The raw uri path.
     *
     * @return string       The RFC 3986 percent-encoded uri path.
     *
     * @link   http://www.faqs.org/rfcs/rfc3986.html
     */
    
protected function filterPath($path): string
    
{
        
$match preg_replace_callback(
            
'/(?:[^a-zA-Z0-9_\-\.~:@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
            function (
$match) {
                return 
rawurlencode($match[0]);
            },
            
$path
        
);

        return 
is_string($match) ? $match '';
    }

    
/**
     * {@inheritdoc}
     */
    
public function getQuery(): string
    
{
        return 
$this->query;
    }

    
/**
     * {@inheritdoc}
     */
    
public function withQuery($query)
    {
        
$query ltrim($this->filterQuery($query), '?');
        
$clone = clone $this;
        
$clone->query $query;

        return 
$clone;
    }

    
/**
     * Filters the query string of a URI.
     *
     * Returns the percent-encoded query string.
     *
     * @param mixed $query The raw uri query string.
     *
     * @return string
     */
    
protected function filterQuery($query): string
    
{
        if (
is_object($query) && method_exists($query'__toString')) {
            
$query = (string) $query;
        }

        if (!
is_string($query)) {
            throw new 
InvalidArgumentException('Uri query must be a string.');
        }

        
$match preg_replace_callback(
            
'/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
            function (
$match) {
                return 
rawurlencode($match[0]);
            },
            
$query
        
);

        return 
is_string($match) ? $match '';
    }

    
/**
     * {@inheritdoc}
     */
    
public function getFragment(): string
    
{
        return 
$this->fragment;
    }

    
/**
     * {@inheritdoc}
     */
    
public function withFragment($fragment)
    {
        
$fragment $this->filterFragment($fragment);
        
$clone = clone $this;
        
$clone->fragment $fragment;

        return 
$clone;
    }

    
/**
     * Filters fragment of a URI.
     *
     * Returns the percent-encoded fragment.
     *
     * @param mixed $fragment The raw uri query string.
     *
     * @return string
     */
    
protected function filterFragment($fragment): string
    
{
        if (
is_object($fragment) && method_exists($fragment'__toString')) {
            
$fragment = (string) $fragment;
        }

        if (!
is_string($fragment)) {
            throw new 
InvalidArgumentException('Uri fragment must be a string.');
        }

        
$fragment ltrim($fragment'#');

        
$match preg_replace_callback(
            
'/(?:[^a-zA-Z0-9_\-\.~!\$&\'\(\)\*\+,;=%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/',
            function (
$match) {
                return 
rawurlencode($match[0]);
            },
            
$fragment
        
);

        return 
is_string($match) ? $match '';
    }

    
/**
     * {@inheritdoc}
     */
    
public function __toString(): string
    
{
        
$scheme $this->getScheme();
        
$authority $this->getAuthority();
        
$path $this->getPath();
        
$query $this->getQuery();
        
$fragment $this->getFragment();

        
$path '/' ltrim($path'/');

        return (
$scheme !== '' $scheme ':' '')
            . (
$authority !== '' '//' $authority '')
            . 
$path
            
. ($query !== '' '?' $query '')
            . (
$fragment !== '' '#' $fragment '');
    }
}