@@ -82,17 +82,17 @@ public static function canonicalize(string $path): string
82
82
83
83
// Replace "~" with user's home directory.
84
84
if ('~ ' === $ path [0 ]) {
85
- $ path = self ::getHomeDirectory ().\ mb_substr ($ path , 1 );
85
+ $ path = self ::getHomeDirectory ().mb_substr ($ path , 1 );
86
86
}
87
87
88
- $ path = \ str_replace ('\\' , '/ ' , $ path );
88
+ $ path = str_replace ('\\' , '/ ' , $ path );
89
89
90
90
[$ root , $ pathWithoutRoot ] = self ::split ($ path );
91
91
92
92
$ canonicalParts = self ::findCanonicalParts ($ root , $ pathWithoutRoot );
93
93
94
94
// Add the root directory again
95
- self ::$ buffer [$ path ] = $ canonicalPath = $ root .\ implode ('/ ' , $ canonicalParts );
95
+ self ::$ buffer [$ path ] = $ canonicalPath = $ root .implode ('/ ' , $ canonicalParts );
96
96
++self ::$ bufferSize ;
97
97
98
98
// Clean up regularly to prevent memory leaks
@@ -152,9 +152,9 @@ public static function getDirectory(string $path): string
152
152
$ path = self ::canonicalize ($ path );
153
153
154
154
// Maintain scheme
155
- if (false !== ($ schemeSeparatorPosition = \ mb_strpos ($ path , ':// ' ))) {
156
- $ scheme = \ mb_substr ($ path , 0 , $ schemeSeparatorPosition + 3 );
157
- $ path = \ mb_substr ($ path , $ schemeSeparatorPosition + 3 );
155
+ if (false !== ($ schemeSeparatorPosition = mb_strpos ($ path , ':// ' ))) {
156
+ $ scheme = mb_substr ($ path , 0 , $ schemeSeparatorPosition + 3 );
157
+ $ path = mb_substr ($ path , $ schemeSeparatorPosition + 3 );
158
158
} else {
159
159
$ scheme = '' ;
160
160
}
@@ -169,11 +169,11 @@ public static function getDirectory(string $path): string
169
169
}
170
170
171
171
// Directory equals Windows root "C:/"
172
- if (2 === $ dirSeparatorPosition && \ ctype_alpha ($ path [0 ]) && ': ' === $ path [1 ]) {
173
- return $ scheme .\ mb_substr ($ path , 0 , 3 );
172
+ if (2 === $ dirSeparatorPosition && ctype_alpha ($ path [0 ]) && ': ' === $ path [1 ]) {
173
+ return $ scheme .mb_substr ($ path , 0 , 3 );
174
174
}
175
175
176
- return $ scheme .\ mb_substr ($ path , 0 , $ dirSeparatorPosition );
176
+ return $ scheme .mb_substr ($ path , 0 , $ dirSeparatorPosition );
177
177
}
178
178
179
179
/**
@@ -193,16 +193,16 @@ public static function getDirectory(string $path): string
193
193
public static function getHomeDirectory (): string
194
194
{
195
195
// For UNIX support
196
- if (\ getenv ('HOME ' )) {
197
- return self ::canonicalize (\ getenv ('HOME ' ));
196
+ if (getenv ('HOME ' )) {
197
+ return self ::canonicalize (getenv ('HOME ' ));
198
198
}
199
199
200
200
// For >= Windows8 support
201
- if (\ getenv ('HOMEDRIVE ' ) && \ getenv ('HOMEPATH ' )) {
202
- return self ::canonicalize (\ getenv ('HOMEDRIVE ' ).\ getenv ('HOMEPATH ' ));
201
+ if (getenv ('HOMEDRIVE ' ) && getenv ('HOMEPATH ' )) {
202
+ return self ::canonicalize (getenv ('HOMEDRIVE ' ).getenv ('HOMEPATH ' ));
203
203
}
204
204
205
- throw new \RuntimeException ("Cannot find the home directory path: Your environment or operation system isn't supported " );
205
+ throw new \RuntimeException ("Cannot find the home directory path: Your environment or operation system isn't supported. " );
206
206
}
207
207
208
208
/**
@@ -234,7 +234,7 @@ public static function getRoot(string $path): string
234
234
return $ scheme .'/ ' ;
235
235
}
236
236
237
- $ length = \ mb_strlen ($ path );
237
+ $ length = mb_strlen ($ path );
238
238
239
239
// Windows root
240
240
if ($ length > 1 && ': ' === $ path [1 ] && ctype_alpha ($ firstCharacter )) {
@@ -258,18 +258,18 @@ public static function getRoot(string $path): string
258
258
* @param string|null $extension if specified, only that extension is cut
259
259
* off (may contain leading dot)
260
260
*/
261
- public static function getFilenameWithoutExtension (string $ path , ? string $ extension = null )
261
+ public static function getFilenameWithoutExtension (string $ path , string $ extension = null )
262
262
{
263
263
if ('' === $ path ) {
264
264
return '' ;
265
265
}
266
266
267
267
if (null !== $ extension ) {
268
268
// remove extension and trailing dot
269
- return \ rtrim (\ basename ($ path , $ extension ), '. ' );
269
+ return rtrim (basename ($ path , $ extension ), '. ' );
270
270
}
271
271
272
- return \ pathinfo ($ path , PATHINFO_FILENAME );
272
+ return pathinfo ($ path , \ PATHINFO_FILENAME );
273
273
}
274
274
275
275
/**
@@ -283,7 +283,7 @@ public static function getExtension(string $path, bool $forceLowerCase = false):
283
283
return '' ;
284
284
}
285
285
286
- $ extension = \ pathinfo ($ path , PATHINFO_EXTENSION );
286
+ $ extension = pathinfo ($ path , \ PATHINFO_EXTENSION );
287
287
288
288
if ($ forceLowerCase ) {
289
289
$ extension = self ::toLower ($ extension );
@@ -326,7 +326,7 @@ public static function hasExtension(string $path, $extensions = null, bool $igno
326
326
}
327
327
328
328
// remove leading '.' in extensions array
329
- $ extensions [$ key ] = \ ltrim ($ extension , '. ' );
329
+ $ extensions [$ key ] = ltrim ($ extension , '. ' );
330
330
}
331
331
332
332
return \in_array ($ actualExtension , $ extensions , true );
@@ -347,19 +347,19 @@ public static function changeExtension(string $path, string $extension): string
347
347
}
348
348
349
349
$ actualExtension = self ::getExtension ($ path );
350
- $ extension = \ ltrim ($ extension , '. ' );
350
+ $ extension = ltrim ($ extension , '. ' );
351
351
352
352
// No extension for paths
353
- if ('/ ' === \ mb_substr ($ path , -1 )) {
353
+ if ('/ ' === mb_substr ($ path , -1 )) {
354
354
return $ path ;
355
355
}
356
356
357
357
// No actual extension in path
358
358
if (empty ($ actualExtension )) {
359
- return $ path .('. ' === \ mb_substr ($ path , -1 ) ? '' : '. ' ).$ extension ;
359
+ return $ path .('. ' === mb_substr ($ path , -1 ) ? '' : '. ' ).$ extension ;
360
360
}
361
361
362
- return \ mb_substr ($ path , 0 , -\ mb_strlen ($ actualExtension )).$ extension ;
362
+ return mb_substr ($ path , 0 , -mb_strlen ($ actualExtension )).$ extension ;
363
363
}
364
364
365
365
public static function isAbsolute (string $ path ): bool
@@ -369,8 +369,8 @@ public static function isAbsolute(string $path): bool
369
369
}
370
370
371
371
// Strip scheme
372
- if (false !== ($ schemeSeparatorPosition = \ mb_strpos ($ path , ':// ' ))) {
373
- $ path = \ mb_substr ($ path , $ schemeSeparatorPosition + 3 );
372
+ if (false !== ($ schemeSeparatorPosition = mb_strpos ($ path , ':// ' ))) {
373
+ $ path = mb_substr ($ path , $ schemeSeparatorPosition + 3 );
374
374
}
375
375
376
376
$ firstCharacter = $ path [0 ];
@@ -381,9 +381,9 @@ public static function isAbsolute(string $path): bool
381
381
}
382
382
383
383
// Windows root
384
- if (\ mb_strlen ($ path ) > 1 && \ ctype_alpha ($ firstCharacter ) && ': ' === $ path [1 ]) {
384
+ if (mb_strlen ($ path ) > 1 && ctype_alpha ($ firstCharacter ) && ': ' === $ path [1 ]) {
385
385
// Special case: "C:"
386
- if (2 === \ mb_strlen ($ path )) {
386
+ if (2 === mb_strlen ($ path )) {
387
387
return true ;
388
388
}
389
389
@@ -441,25 +441,25 @@ public static function isRelative(string $path): bool
441
441
public static function makeAbsolute (string $ path , string $ basePath ): string
442
442
{
443
443
if ('' === $ basePath ) {
444
- throw new InvalidArgumentException (\ sprintf ('The base path must be a non-empty string. Got: "%s" ' , $ basePath ));
444
+ throw new InvalidArgumentException (sprintf ('The base path must be a non-empty string. Got: "%s" ' , $ basePath ));
445
445
}
446
446
447
447
if (!self ::isAbsolute ($ basePath )) {
448
- throw new InvalidArgumentException (\ sprintf ('The base path "%s" is not an absolute path. ' , $ basePath ));
448
+ throw new InvalidArgumentException (sprintf ('The base path "%s" is not an absolute path. ' , $ basePath ));
449
449
}
450
450
451
451
if (self ::isAbsolute ($ path )) {
452
452
return self ::canonicalize ($ path );
453
453
}
454
454
455
- if (false !== ($ schemeSeparatorPosition = \ mb_strpos ($ basePath , ':// ' ))) {
456
- $ scheme = \ mb_substr ($ basePath , 0 , $ schemeSeparatorPosition + 3 );
457
- $ basePath = \ mb_substr ($ basePath , $ schemeSeparatorPosition + 3 );
455
+ if (false !== ($ schemeSeparatorPosition = mb_strpos ($ basePath , ':// ' ))) {
456
+ $ scheme = mb_substr ($ basePath , 0 , $ schemeSeparatorPosition + 3 );
457
+ $ basePath = mb_substr ($ basePath , $ schemeSeparatorPosition + 3 );
458
458
} else {
459
459
$ scheme = '' ;
460
460
}
461
461
462
- return $ scheme .self ::canonicalize (\ rtrim ($ basePath , '/ \\' ).'/ ' .$ path );
462
+ return $ scheme .self ::canonicalize (rtrim ($ basePath , '/ \\' ).'/ ' .$ path );
463
463
}
464
464
465
465
/**
@@ -526,7 +526,7 @@ public static function makeRelative(string $path, string $basePath): string
526
526
if ('' === $ root && '' !== $ baseRoot ) {
527
527
// If base path is already in its root
528
528
if ('' === $ relativeBasePath ) {
529
- $ relativePath = \ ltrim ($ relativePath , './ \\' );
529
+ $ relativePath = ltrim ($ relativePath , './ \\' );
530
530
}
531
531
532
532
return $ relativePath ;
@@ -535,21 +535,21 @@ public static function makeRelative(string $path, string $basePath): string
535
535
// If the passed path is absolute, but the base path is not, we
536
536
// cannot generate a relative path
537
537
if ('' !== $ root && '' === $ baseRoot ) {
538
- throw new InvalidArgumentException (\ sprintf ('The absolute path "%s" cannot be made relative to the relative path "%s". You should provide an absolute base path instead. ' , $ path , $ basePath ));
538
+ throw new InvalidArgumentException (sprintf ('The absolute path "%s" cannot be made relative to the relative path "%s". You should provide an absolute base path instead. ' , $ path , $ basePath ));
539
539
}
540
540
541
541
// Fail if the roots of the two paths are different
542
542
if ($ baseRoot && $ root !== $ baseRoot ) {
543
- throw new InvalidArgumentException (\ sprintf ('The path "%s" cannot be made relative to "%s", because they have different roots ("%s" and "%s"). ' , $ path , $ basePath , $ root , $ baseRoot ));
543
+ throw new InvalidArgumentException (sprintf ('The path "%s" cannot be made relative to "%s", because they have different roots ("%s" and "%s"). ' , $ path , $ basePath , $ root , $ baseRoot ));
544
544
}
545
545
546
546
if ('' === $ relativeBasePath ) {
547
547
return $ relativePath ;
548
548
}
549
549
550
550
// Build a "../../" prefix with as many "../" parts as necessary
551
- $ parts = \ explode ('/ ' , $ relativePath );
552
- $ baseParts = \ explode ('/ ' , $ relativeBasePath );
551
+ $ parts = explode ('/ ' , $ relativePath );
552
+ $ baseParts = explode ('/ ' , $ relativeBasePath );
553
553
$ dotDotPrefix = '' ;
554
554
555
555
// Once we found a non-matching part in the prefix, we need to add
@@ -567,15 +567,15 @@ public static function makeRelative(string $path, string $basePath): string
567
567
$ dotDotPrefix .= '../ ' ;
568
568
}
569
569
570
- return \ rtrim ($ dotDotPrefix .\ implode ('/ ' , $ parts ), '/ ' );
570
+ return rtrim ($ dotDotPrefix .implode ('/ ' , $ parts ), '/ ' );
571
571
}
572
572
573
573
/**
574
574
* Returns whether the given path is on the local filesystem.
575
575
*/
576
576
public static function isLocal (string $ path ): bool
577
577
{
578
- return '' !== $ path && false === \ mb_strpos ($ path , ':// ' );
578
+ return '' !== $ path && false === mb_strpos ($ path , ':// ' );
579
579
}
580
580
581
581
/**
@@ -616,10 +616,10 @@ public static function isLocal(string $path): bool
616
616
*/
617
617
public static function getLongestCommonBasePath (string ...$ paths ): ?string
618
618
{
619
- [$ bpRoot , $ basePath ] = self ::split (self ::canonicalize (\ reset ($ paths )));
619
+ [$ bpRoot , $ basePath ] = self ::split (self ::canonicalize (reset ($ paths )));
620
620
621
- for (\ next ($ paths ); null !== \ key ($ paths ) && '' !== $ basePath ; \ next ($ paths )) {
622
- [$ root , $ path ] = self ::split (self ::canonicalize (\ current ($ paths )));
621
+ for (next ($ paths ); null !== key ($ paths ) && '' !== $ basePath ; next ($ paths )) {
622
+ [$ root , $ path ] = self ::split (self ::canonicalize (current ($ paths )));
623
623
624
624
// If we deal with different roots (e.g. C:/ vs. D:/), it's time
625
625
// to quit
@@ -639,7 +639,7 @@ public static function getLongestCommonBasePath(string ...$paths): ?string
639
639
640
640
// Prevent false positives for common prefixes
641
641
// see isBasePath()
642
- if (0 === \ mb_strpos ($ path .'/ ' , $ basePath .'/ ' )) {
642
+ if (0 === mb_strpos ($ path .'/ ' , $ basePath .'/ ' )) {
643
643
// next path
644
644
continue 2 ;
645
645
}
@@ -667,17 +667,17 @@ public static function join(string ...$paths): string
667
667
if (null === $ finalPath ) {
668
668
// For first part we keep slashes, like '/top', 'C:\' or 'phar://'
669
669
$ finalPath = $ path ;
670
- $ wasScheme = (false !== \ mb_strpos ($ path , ':// ' ));
670
+ $ wasScheme = (false !== mb_strpos ($ path , ':// ' ));
671
671
continue ;
672
672
}
673
673
674
674
// Only add slash if previous part didn't end with '/' or '\'
675
- if (!\in_array (\ mb_substr ($ finalPath , -1 ), ['/ ' , '\\' ])) {
675
+ if (!\in_array (mb_substr ($ finalPath , -1 ), ['/ ' , '\\' ])) {
676
676
$ finalPath .= '/ ' ;
677
677
}
678
678
679
679
// If first part included a scheme like 'phar://' we allow \current part to start with '/', otherwise trim
680
- $ finalPath .= $ wasScheme ? $ path : \ ltrim ($ path , '/ ' );
680
+ $ finalPath .= $ wasScheme ? $ path : ltrim ($ path , '/ ' );
681
681
$ wasScheme = false ;
682
682
}
683
683
@@ -718,15 +718,15 @@ public static function isBasePath(string $basePath, string $ofPath): bool
718
718
// Don't append a slash for the root "/", because then that root
719
719
// won't be discovered as common prefix ("//" is not a prefix of
720
720
// "/foobar/").
721
- return 0 === \ mb_strpos ($ ofPath .'/ ' , \ rtrim ($ basePath , '/ ' ).'/ ' );
721
+ return 0 === mb_strpos ($ ofPath .'/ ' , rtrim ($ basePath , '/ ' ).'/ ' );
722
722
}
723
723
724
724
/**
725
725
* @return non-empty-string[]
726
726
*/
727
727
private static function findCanonicalParts (string $ root , string $ pathWithoutRoot ): array
728
728
{
729
- $ parts = \ explode ('/ ' , $ pathWithoutRoot );
729
+ $ parts = explode ('/ ' , $ pathWithoutRoot );
730
730
731
731
$ canonicalParts = [];
732
732
@@ -739,7 +739,7 @@ private static function findCanonicalParts(string $root, string $pathWithoutRoot
739
739
// Collapse ".." with the previous part, if one exists
740
740
// Don't collapse ".." if the previous part is also ".."
741
741
if ('.. ' === $ part && \count ($ canonicalParts ) > 0 && '.. ' !== $ canonicalParts [\count ($ canonicalParts ) - 1 ]) {
742
- \ array_pop ($ canonicalParts );
742
+ array_pop ($ canonicalParts );
743
743
744
744
continue ;
745
745
}
@@ -777,28 +777,28 @@ private static function split(string $path): array
777
777
}
778
778
779
779
// Remember scheme as part of the root, if any
780
- if (false !== ($ schemeSeparatorPosition = \ mb_strpos ($ path , ':// ' ))) {
781
- $ root = \ mb_substr ($ path , 0 , $ schemeSeparatorPosition + 3 );
782
- $ path = \ mb_substr ($ path , $ schemeSeparatorPosition + 3 );
780
+ if (false !== ($ schemeSeparatorPosition = mb_strpos ($ path , ':// ' ))) {
781
+ $ root = mb_substr ($ path , 0 , $ schemeSeparatorPosition + 3 );
782
+ $ path = mb_substr ($ path , $ schemeSeparatorPosition + 3 );
783
783
} else {
784
784
$ root = '' ;
785
785
}
786
786
787
- $ length = \ mb_strlen ($ path );
787
+ $ length = mb_strlen ($ path );
788
788
789
789
// Remove and remember root directory
790
- if (0 === \ mb_strpos ($ path , '/ ' )) {
790
+ if (0 === mb_strpos ($ path , '/ ' )) {
791
791
$ root .= '/ ' ;
792
- $ path = $ length > 1 ? \ mb_substr ($ path , 1 ) : '' ;
793
- } elseif ($ length > 1 && \ ctype_alpha ($ path [0 ]) && ': ' === $ path [1 ]) {
792
+ $ path = $ length > 1 ? mb_substr ($ path , 1 ) : '' ;
793
+ } elseif ($ length > 1 && ctype_alpha ($ path [0 ]) && ': ' === $ path [1 ]) {
794
794
if (2 === $ length ) {
795
795
// Windows special case: "C:"
796
796
$ root .= $ path .'/ ' ;
797
797
$ path = '' ;
798
798
} elseif ('/ ' === $ path [2 ]) {
799
799
// Windows normal case: "C:/"..
800
- $ root .= \ mb_substr ($ path , 0 , 3 );
801
- $ path = $ length > 3 ? \ mb_substr ($ path , 3 ) : '' ;
800
+ $ root .= mb_substr ($ path , 0 , 3 );
801
+ $ path = $ length > 3 ? mb_substr ($ path , 3 ) : '' ;
802
802
}
803
803
}
804
804
@@ -808,10 +808,10 @@ private static function split(string $path): array
808
808
private static function toLower (string $ string ): string
809
809
{
810
810
if (false !== $ encoding = mb_detect_encoding ($ string )) {
811
- return \ mb_strtolower ($ string , $ encoding );
811
+ return mb_strtolower ($ string , $ encoding );
812
812
}
813
813
814
- return \ strtolower ($ string , $ encoding );
814
+ return strtolower ($ string , $ encoding );
815
815
}
816
816
817
817
private function __construct ()
0 commit comments