-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUri.php
1937 lines (1458 loc) · 53.3 KB
/
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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <[email protected]>
* License: https://github.com/quidphp/base/blob/master/LICENSE
*/
namespace Quid\Base;
// uri
// class with static methods to generate URI (absolute and relative)
final class Uri extends Root
{
// trait
use _option;
use _shortcut;
// config
protected static array $config = [
'option'=>[ // tableau d'options
'absolute'=>null, // si l'uri doit être absolute
'schemeHost'=>null, // schemehost pour uri relative passé dans une méthode absolute, aussi pour exists
'encode'=>true, // l'uri out doit être encodé
'decode'=>false, // l'uri in doit être décodé
'append'=>false, // ce qu'il faut append aux uri, true signifie timestamp
'exists'=>false, // vérifie si le uri existe sur le serveur
'notFoundCallable'=>[Error::class,'trigger']], // callable si l'uri n'existe pas
'protocolRelative'=>'//', // caractère pour désigner un chemin protocol-relative
'query'=>[ // paramètres pour la construction et encodage des query
'parse'=>['+'=>'%2B'], // remplacement pour parse_str
'separator'=>['&','&'], // séparateur pour http_build_query
'encoding'=>PHP_QUERY_RFC3986, // encodage pour http_build_query
'default'=>'t'], // clé de query a utilisé si append est true
'parseConstant'=>[ // tableau liant des strings aux constantes
'scheme'=>PHP_URL_SCHEME,
'user'=>PHP_URL_USER,
'pass'=>PHP_URL_PASS,
'host'=>PHP_URL_HOST,
'port'=>PHP_URL_PORT,
'path'=>PHP_URL_PATH,
'query'=>PHP_URL_QUERY,
'fragment'=>PHP_URL_FRAGMENT],
'scheme'=>['http','https','ftp'], // scheme accepté par la méthode isSchemeValid
'build'=>[ // pour reconstruire à partir d'un array
'scheme'=>'://',
'user'=>'',
'pass'=>':',
'host'=>'@',
'port'=>':',
'path'=>'/',
'query'=>'?',
'fragment'=>'#'],
'redirection'=>'*' // caractère pour les redirections via tableau
];
// absolute
protected static bool $absolute = false; // détermine si toutes les requêtes dans output doivent être absolute
// scheme
protected static array $scheme = []; // tableau associatif entre host et scheme
// is
// retourne vrai si la valeur est uri relative ou absolut
final public static function is($value,bool $decode=false):bool
{
return is_string($value) && self::info($value,$decode)['type'] !== false;
}
// isRelative
// retourne vrai si la valeur est uri relative
final public static function isRelative($value):bool
{
$return = false;
if(is_string($value))
{
$type = self::type($value);
$return = ($type === 'relative');
}
return $return;
}
// isAbsolute
// retourne vrai si la valeur est uri absolute
final public static function isAbsolute($value):bool
{
$return = false;
if(is_string($value))
{
$type = self::type($value);
$return = ($type === 'absolute');
}
return $return;
}
// isSsl
// retourne vrai si l'uri est https
final public static function isSsl(string $uri,bool $decode=false):bool
{
return self::scheme($uri,$decode) === Http::scheme(true);
}
// isSchemeValid
// retourne vrai si le scheme est supporté par la classe
final public static function isSchemeValid($value):bool
{
return is_string($value) && in_array(strtolower($value),self::$config['scheme'],true);
}
// isSchemeProtocolRelative
// retourne vrai si le scheme est relatif au protocl
final public static function isSchemeProtocolRelative(string $uri):bool
{
return substr($uri,0,2) === self::$config['protocolRelative'];
}
// hasScheme
// retourne vrai si l'uri a un scheme
final public static function hasScheme(string $uri,bool $decode=false):bool
{
return !empty(self::scheme($uri,$decode));
}
// hasExtension
// retourne vrai si le chemin a une extension
final public static function hasExtension(string $uri,bool $decode=false):bool
{
return !empty(self::extension($uri,$decode));
}
// hasQuery
// retourne vrai si le chemin a un query
final public static function hasQuery(string $uri,bool $decode=false):bool
{
return !empty(self::query($uri,$decode));
}
// hasLang
// retourne vrai si l'uri a une lang
final public static function hasLang(string $uri,bool $decode=false):bool
{
return self::lang($uri,$decode) !== null;
}
// isInternal
// retourne vrai si l'uri donné est interne
// un ou plusieurs host peut être fourni, sinon utilise celui de request
// si l'uri n'a pas de host, retourne vrai
final public static function isInternal(string $value,$host=null):bool
{
$return = true;
if(self::isAbsolute($value))
{
if(empty($host))
$host = Request::host();
$return = (self::isHost($host,$value));
}
return $return;
}
// isExternal
// retourne vrai si l'uri donné est externe
// un host ou plusieurs peut être fourni, sinon utilise celui de request
// si l'uri n'a pas de host, retourne faux
final public static function isExternal(string $value,$host=null):bool
{
$return = false;
if(self::isAbsolute($value))
{
if(empty($host))
$host = Request::host();
$return = (!self::isHost($host,$value));
}
return $return;
}
// isFragment
// retourne vrai si l'url commence par le caractère de fragment
final public static function isFragment($value):bool
{
return is_string($value) && strpos($value,self::$config['build']['fragment']) === 0;
}
// isScheme
// retourne vrai si l'uri a un scheme du type spécifié
final public static function isScheme($value,string $uri,bool $decode=false):bool
{
$return = false;
$scheme = self::scheme($uri,$decode);
if(is_string($value) && $value === $scheme)
$return = true;
elseif(is_bool($value) && Http::scheme($value) === $scheme)
$return = true;
return $return;
}
// isHost
// retourne vrai si l'uri a l'hôte spécifié
// possibilité de mettre une ou plusieurs target
// comparaison insensible à la case
final public static function isHost($target,string $uri,bool $decode=false):bool
{
$return = false;
if(is_string($target) || is_array($target))
{
$host = self::host($uri,$decode);
$return = (!empty($host) && Arr::in($host,(array) $target,false));
}
return $return;
}
// isSchemeHost
// retourne vrai si l'uri a le scheme host spécifié
final public static function isSchemeHost($value,string $uri,bool $decode=false):bool
{
$schemeHost = self::schemeHost($uri,$decode);
return is_string($value) && $value === $schemeHost;
}
// isExtension
// retourne vrai si l'uri à une extension du type
// possibilité de mettre une ou plusieurs target
// comparaison insensible à la case
final public static function isExtension($target,string $uri,bool $decode=false):bool
{
$return = false;
if(is_string($target) || is_array($target))
{
$extension = self::extension($uri,$decode);
$return = (!empty($extension) && Arr::in($extension,(array) $target,false));
}
return $return;
}
// isQuery
// retourne vrai si l'uri a des query
// keys permet de retourner vrai si une ou plusieurs key de get sont présents
final public static function isQuery($keys,string $uri,bool $decode=false):bool
{
$return = false;
if(is_string($keys) || is_array($keys))
{
$keys = (array) $keys;
$query = self::queryArray($uri,true,$decode);
$return = (Arr::keysExists($keys,$query));
}
return $return;
}
// isLang
// retourne vrai si l'uri a la langue spécifié
final public static function isLang($value,string $uri,bool $decode=false):bool
{
return is_string($value) && $value === self::lang($uri,$decode);
}
// sameSchemeHost
// retourne vrai si les deux uris ont le même schemeHost
final public static function sameSchemeHost($value,string $uri,bool $decode=false):bool
{
$schemeHost = self::schemeHost($uri,$decode);
return is_string($value) && self::schemeHost($value,$decode) === $schemeHost;
}
// areAllAbsolute
// retourne vrai si toutes les urls générés par output doivent être en absolute
final public static function areAllAbsolute():bool
{
return self::$absolute;
}
// type
// retourne rapidement le type de l'uri
final public static function type(string $uri,bool $decode=false):?string
{
$return = null;
if(self::isSchemeProtocolRelative($uri))
$return = 'absolute';
elseif(strpos($uri,'http:') === 0)
$return = 'absolute';
elseif(strpos($uri,'https:') === 0)
$return = 'absolute';
elseif(strpos($uri,'ftp:') === 0)
$return = 'absolute';
elseif(strpos($uri,'/') === 0)
$return = 'relative';
return $return;
}
// output
// format et encode une uri
// peut être relative, absolute ou tel que fourni
// si areAllAbsolute est true, et que la valeur n'est pas un fragment, alors on peut forcer l'absolute (passe par-dessus les options)
final public static function output(string $return,?array $option=null):string
{
$return = self::shortcut($return);
$option = self::option($option);
$absolute = $option['absolute'] ?? null;
$schemeHost = $option['schemeHost'] ?? self::schemeHost($return);
if(self::areAllAbsolute() && !self::isFragment($return))
$return = self::absolute($return,$schemeHost,$option);
else
{
if(is_string($schemeHost) && !empty($schemeHost) && $absolute === null)
$option['absolute'] = (Request::isSchemeHost($schemeHost) || Request::isHost($schemeHost))? false:true;
if($option['absolute'] === false)
$return = self::relative($return,$option);
elseif($option['absolute'] === true || self::isAbsolute($return))
$return = self::absolute($return,$schemeHost,$option);
else
$return = self::relative($return,$option);
}
return $return;
}
// outputExists
// output une uri avec option exists à true
final public static function outputExists(string $uri,?array $option=null):string
{
return self::output($uri,self::option(Arr::plus($option,['exists'=>true])));
}
// relative
// output une uri en relatif
// si return est vide, retourne /
final public static function relative(string $return,?array $option=null):string
{
$return = self::shortcut($return);
$option = self::option($option);
if(self::isAbsolute($return))
$return = self::removeBefore('path',$return,$option['decode']);
if($return !== '#')
{
if($return === '')
$return = '/';
if(strlen($return))
{
if(!empty($option['append']))
$return = self::append($option['append'],$return);
if($option['encode'] === true)
$return = self::encodeAll($return,$option['decode']);
if($option['exists'] === true && self::isCallable($option['notFoundCallable']))
{
$host = (is_string($option['schemeHost']))? $option['schemeHost']:Request::schemeHost();
if(!Finder::isUriToPath($return,$host))
$return = self::existsCallable($return,$option['notFoundCallable']);
}
}
}
return $return;
}
// absolute
// output une uri en absolute
// une uri avec un scheme et un nom de domaine peut être fourni
// si pas de scheme domain fournit, utilise current scheme/domain de request
// l'option exists est seulement déclenché si le host de l'uri est présent dans finder/host
final public static function absolute(string $return,$schemeHost=null,?array $option=null):string
{
$return = self::shortcut($return);
$option = self::option($option);
if(!self::isAbsolute($return))
{
if(is_string($schemeHost) && !empty($schemeHost))
{
$static = self::getSchemeHostStatic($schemeHost);
if(is_string($static))
$schemeHost = $static;
}
if(empty($schemeHost))
$schemeHost = (!empty($option['schemeHost']))? $option['schemeHost']:Request::schemeHost();
if(!empty($schemeHost))
{
$scheme = self::scheme($schemeHost);
if($scheme === null)
$schemeHost = self::changeScheme(Request::scheme(),$schemeHost);
$return = self::combine($schemeHost,$return,'path',$option['decode']);
}
}
if(strlen($return))
{
$return = self::changeProtocolRelativeScheme($return);
if(!empty($option['append']))
$return = self::append($option['append'],$return);
if($option['encode'] === true)
$return = self::encodeAll($return,$option['decode']);
if($option['exists'] === true && self::isCallable($option['notFoundCallable']))
{
$host = self::host($return);
if(Finder::isHost($host) && !Finder::isUriToPath($return))
$return = self::existsCallable($return,$option['notFoundCallable']);
}
}
return $return;
}
// existsCallable
// utilisé par relative et absolute pour vérifier l'existence du fichier à partir d'une uri
// si la callable retourne une string, il est considéré que c'est une uri de remplacement
final public static function existsCallable(string $uri,callable $callable):?string
{
$return = null;
$result = $callable($uri);
if(is_string($result))
$return = $result;
return $return;
}
// append
// gère l'ajout automatique de contenu à la fin de uri
// si value est true, ça signifie timestamp et utilise la clé query par défaut
// si dans le tableau, value est true ça signifie timestamp
final public static function append($value,string $return,bool $cast=true,bool $encode=false,bool $decode=false):string
{
$query = [];
if($value === true && is_string(self::$config['query']['default']))
$value = [self::$config['query']['default']=>$value];
if(is_array($value))
{
foreach ($value as $k => $v)
{
if(is_scalar($v))
{
if($v === true)
$v = Datetime::time();
$query[$k] = $v;
}
}
}
if(!empty($query))
$return = self::setsQuery($query,$return,$cast,$encode,$decode);
return $return;
}
// encode
// wrapper pour la fonction d'encodage
// par défaut, utilise rawurlencode
final public static function encode(string $return,int $type=0)
{
if($type === 0)
$return = rawurlencode($return);
if($type === 1)
$return = urlencode($return);
return $return;
}
// decode
// wrapper pour la fonction de décodage
// par défaut, utilise rawurldecode
final public static function decode(string $return,int $type=0):?string
{
if($type === 0)
$return = rawurldecode($return);
if($type === 1)
$return = urldecode($return);
if(!empty(self::$config['query']['separator']))
$return = str_replace(self::$config['query']['separator'][1],self::$config['query']['separator'][0],$return);
return $return;
}
// encodeAll
// encode toutes les partis de l'uri
final public static function encodeAll(string $uri,bool $decode=false):string
{
$parse = self::parse($uri,$decode);
foreach ($parse as $key => $value)
{
if(is_string($value))
{
if($key === 'fragment')
$parse[$key] = self::encode($value);
elseif($key === 'path')
$parse[$key] = self::encodePath($value);
elseif($key === 'query')
$parse[$key] = self::encodeQuery($value);
}
}
return self::build($parse,false);
}
// encodePath
// encode les différentes étages du path uri
final public static function encodePath(string $path):string
{
$array = [];
$separatorEnd = Path::isSeparatorEnd($path);
foreach (Path::arr($path) as $key => $value)
{
$array[$key] = self::encode($value);
}
$return = Path::str($array,['end'=>$separatorEnd]);
return $return;
}
// encodeQuery
// encode le query
final public static function encodeQuery(string $query):string
{
$array = self::parseQuery($query);
$return = self::buildQuery($array,true);
return $return;
}
// parseQuery
// prend une chaîne de type get et retourne un array
final public static function parseQuery(string $query,bool $cast=true,?bool $mb=null):array
{
$return = [];
$mb = Encoding::getMb($mb,$query);
$replace = self::$config['query']['parse'];
if(!empty($replace))
$query = Str::replace($replace,$query);
if($mb === true)
mb_parse_str($query,$return);
else
parse_str($query,$return);
if($cast === true)
$return = Arr::cast($return);
return $return;
}
// buildQuery
// prend un array et retourne une string de type query
final public static function buildQuery(array $query,bool $encode=false):?string
{
$return = null;
$separator = ($encode === false)? self::$config['query']['separator'][1]:self::$config['query']['separator'][0];
$encoding = self::$config['query']['encoding'];
$return = http_build_query($query,'',$separator,$encoding);
if($encode === false)
$return = self::decode($return);
return $return ?: null;
}
// parse
// decode et parse_url
// les shortcut sont remplacés
final public static function parse(string $uri,bool $decode=false):?array
{
$return = null;
$uri = self::shortcut($uri);
if($decode === true)
$uri = self::decode($uri);
$parse = parse_url($uri,-1);
if(is_array($parse))
{
$return = ['scheme'=>null,'user'=>null,'pass'=>null,'host'=>null,'port'=>null,'path'=>null,'query'=>null,'fragment'=>null];
if(self::isSchemeProtocolRelative($uri))
$return['scheme'] = Request::scheme();
foreach ($parse as $key => $value)
{
$return[$key] = $value;
}
}
return $return;
}
// parseOne
// decode et parse_url
// les shortcut sont remplacés
// retourne une partie de l'uri
final public static function parseOne($key,string $uri,bool $decode=false)
{
$return = null;
if(is_string($key))
$key = self::getParseConstant($key);
if(is_int($key))
{
$uri = self::shortcut($uri);
if($decode === true)
$uri = self::decode($uri);
$return = parse_url($uri,$key);
if($return === false || $return === '')
$return = null;
}
return $return;
}
// getParseConstant
// retourne la constante à partir d'une string
// utilisé pour parse_url
final public static function getParseConstant(string $key):?int
{
return self::$config['parseConstant'][$key] ?? null;
}
// getEmptyParse
// retourne un tableau vide similaire au retour de parse_url
final public static function getEmptyParse():array
{
return Arr::valuesAll(null,self::$config['parseConstant']);
}
// info
// retourne un tableau d'information sur l'uri
final public static function info(string $uri,bool $decode=false):array
{
$return = [];
$parse = self::parse($uri,$decode);
$return['source'] = $uri;
$return['type'] = false;
$return['protocolRelative'] = false;
$return['ssl'] = false;
$return['parse'] = $parse;
$return['pathinfo'] = ['dirname'=>null,'basename'=>null,'filename'=>null,'extension'=>null];
// scheme
if(!empty($parse['scheme']) && $parse['scheme'] === 'https')
$return['ssl'] = true;
// host
if(!empty($parse['host']))
{
// protocol-relative scheme
if(self::isSchemeProtocolRelative($uri))
{
$return['type'] = 'absolute';
$return['protocolRelative'] = true;
$return['parse']['scheme'] = Request::scheme();
}
elseif(!empty($parse['scheme']))
$return['type'] = 'absolute';
}
// path
if(!empty($parse['path']))
{
// pathinfo
$pathinfo = self::pathinfo($parse['path']);
if($pathinfo !== null)
$return['pathinfo'] = array_merge($return['pathinfo'],$pathinfo);
// vérifie relative
if(empty($return['type']) && Path::isSeparatorStart($parse['path']))
$return['type'] = 'relative';
}
return $return;
}
// scheme
// retourne le scheme de l'uri
final public static function scheme($value,bool $decode=false):?string
{
$return = null;
if(is_bool($value) || is_int($value))
$return = Http::scheme($value);
elseif(is_string($value))
{
if(in_array($value,['http','https'],true))
$return = $value;
elseif(self::isSchemeProtocolRelative($value))
{
$host = self::host($value);
if(is_string($host))
$return = self::getSchemeStatic($host);
if(empty($return))
$return = Request::scheme();
}
else
$return = self::parseOne('scheme',$value,$decode);
}
return $return ?: null;
}
// changeScheme
// change le scheme d'une uri
// ajoute le scheme si le uri n'a pas de scheme
final public static function changeScheme($scheme,string $uri,bool $decode=false):string
{
$return = '';
$scheme = self::scheme($scheme,$decode);
$uriScheme = self::scheme($uri,$decode);
if($uriScheme === null && is_string($scheme))
$uri = $scheme.'://'.$uri;
$return = self::change(['scheme'=>$scheme],$uri,$decode);
return $return;
}
// changeProtocolRelativeScheme
// change le scheme d'une uri si le scheme actuelle est relative au procole
final public static function changeProtocolRelativeScheme(string $return,bool $decode=false)
{
if(self::isSchemeProtocolRelative($return))
{
$scheme = self::scheme($return,$decode);
$return = self::changeScheme($scheme,$return,$decode);
}
return $return;
}
// removeScheme
// enlève le scheme d'une uri
final public static function removeScheme(string $uri,bool $decode=false):string
{
return self::remove('scheme',$uri,$decode);
}
// user
// retourne le username de l'uri
final public static function user(string $uri,bool $decode=false):?string
{
return self::parseOne('user',$uri,$decode);
}
// changeUser
// change le user d'une uri
final public static function changeUser($user,string $uri,bool $decode=false):string
{
return self::change(['user'=>$user],$uri,$decode);
}
// removeUser
// enlève le user d'une uri
final public static function removeUser(string $uri,bool $decode=false):string
{
return self::remove('user',$uri,$decode);
}
// pass
// retourne le password de l'uri
final public static function pass(string $uri,bool $decode=false):?string
{
return self::parseOne('pass',$uri,$decode);
}
// changePass
// change le pass d'une uri
final public static function changePass($pass,string $uri,bool $decode=false):string
{
return self::change(['pass'=>$pass],$uri,$decode);
}
// removePass
// enlève le pass d'une uri
final public static function removePass(string $uri,bool $decode=false):string
{
return self::remove('pass',$uri,$decode);
}
// host
// retourne le host de l'uri
final public static function host(string $uri,bool $decode=false):?string
{
return self::parseOne('host',$uri,$decode);
}
// changeHost
// change le host d'une uri
final public static function changeHost($host,string $uri,bool $decode=false):string
{
return self::change(['host'=>$host],$uri,$decode);
}
// removeHost
// enlève le host d'une uri
final public static function removeHost(string $uri,bool $decode=false):string
{
return self::remove('host',$uri,$decode);
}
// port
// retourne le port de l'uri
final public static function port(string $uri,bool $decode=false):?int
{
return self::parseOne('port',$uri,$decode);
}
// changePort
// change le port d'une uri
final public static function changePort($port,string $uri,bool $decode=false):string
{
return self::change(['port'=>$port],$uri,$decode);
}
// removePort
// enlève le port d'une uri
final public static function removePort(string $uri,bool $decode=false):string
{
return self::remove('port',$uri,$decode);
}
// path
// retourne le path de l'uri
final public static function path(string $uri,bool $decode=false):?string
{
return self::parseOne('path',$uri,$decode);
}
// pathStripStart
// retourne le path de l'uri sans le séparateur au début
final public static function pathStripStart(string $uri,bool $decode=false):?string
{
$return = self::path($uri,$decode);
if(!is_string($return))
$return = null;
else
$return = Path::stripStart($return);
return $return;
}
// changePath
// change le path d'une uri
final public static function changePath($path,string $uri,bool $decode=false):string
{
return self::change(['path'=>$path],$uri,$decode);
}
// removePath
// enlève le path d'une uri
final public static function removePath(string $uri,bool $decode=false):string
{
return self::remove('path',$uri,$decode);
}
// pathinfo
// retourne le tableau pathinfo
final public static function pathinfo(string $uri,bool $decode=false):?array
{
$return = null;
$path = self::path($uri,$decode);
if(is_string($path))
$return = Path::info($path);
return $return;
}
// pathInfoOne
// retourne une entrée du tableau de pathinfo
final public static function pathinfoOne($key,string $uri,bool $decode=false):?string
{
$return = null;
$path = self::path($uri,$decode);
if(is_string($path))