@@ -207,12 +207,12 @@ public function cleanPath(string $path): string
207
207
}
208
208
}
209
209
210
- if ($ path != ' / ' ) {
211
- $ beautifiedPath = implode ( DIRECTORY_SEPARATOR , $ cleanDirs );
210
+ if ($ path != DIRECTORY_SEPARATOR ) {
211
+ $ beautifiedPath = $ this -> makePath (... $ cleanDirs );
212
212
}
213
213
214
214
if (empty ($ beautifiedPath )) {
215
- $ beautifiedPath = (substr ($ path , 0 , 1 ) == ' / ' ) ? ' / ' : '. ' ;
215
+ $ beautifiedPath = (substr ($ path , 0 , 1 ) == DIRECTORY_SEPARATOR ) ? DIRECTORY_SEPARATOR : '. ' ;
216
216
}
217
217
218
218
return $ beautifiedPath ;
@@ -275,7 +275,7 @@ public function getAliases(): array
275
275
*/
276
276
public function newAlias (string $ key , string $ val )
277
277
{
278
- if (substr ($ val , -1 ) == ' / ' ) {
278
+ if (substr ($ val , -1 ) == DIRECTORY_SEPARATOR ) {
279
279
$ val = substr ($ val , 0 , -1 );
280
280
}
281
281
@@ -324,17 +324,28 @@ public function toInternalPath(string $path): string
324
324
return $ internalPath ;
325
325
}
326
326
327
+ // Remove root path
327
328
if (substr ($ internalPath , 0 , strlen ($ this ->rootPath ())) == $ this ->rootPath ()) {
328
- $ internalPath = str_replace ( $ this ->rootPath (), ' ./ ' , $ internalPath );
329
+ $ internalPath = substr ( $ internalPath , strlen ( $ this ->rootPath ()) );
329
330
} else {
330
331
$ realRootPath = realpath ($ this ->rootPath ());
331
332
if (substr ($ internalPath , 0 , strlen ($ realRootPath )) == $ realRootPath ) {
332
333
$ internalPath = substr ($ internalPath , strlen ($ realRootPath ));
333
334
}
334
335
}
335
336
336
- // Convert relative path to absolute path
337
- if (preg_match ('#^(\.)+/# ' , $ internalPath )) {
337
+ // Remove workdir if any
338
+ if (substr ($ internalPath , 0 , strlen ($ this ->workingDir ())) == $ this ->workingDir ()) {
339
+ $ internalPath = str_replace ($ this ->workingDir (), '. ' , $ internalPath );
340
+ } else {
341
+ $ realPath = realpath ($ this ->workingDir ());
342
+ if (substr ($ internalPath , 0 , strlen ($ realPath )) == $ realPath ) {
343
+ $ internalPath = substr ($ internalPath , strlen ($ realPath ));
344
+ }
345
+ }
346
+
347
+ // Append workdir
348
+ if (preg_match ('#^(\.)+ \\' . DIRECTORY_SEPARATOR . '# ' , $ internalPath )) {
338
349
$ internalPath = $ this ->makePath ($ this ->workingDir (), $ internalPath );
339
350
}
340
351
@@ -548,26 +559,13 @@ protected function pathInfo(string $path, int $info): string
548
559
return "file " ;
549
560
}
550
561
}
551
- break ;
552
562
553
563
case PATHINFO_FILENAME :
554
564
$ basename = basename ($ internalPath );
555
565
return substr ($ basename , 0 , strrpos ($ basename , '. ' ));
556
566
557
567
case PATHINFO_DIRNAME :
558
- if (strpos ($ path , "/ " , 1 ) !== false ) {
559
- $ dirname = preg_replace ('#/[^/]*/?$# ' , '' , $ path );
560
- } elseif (strpos ($ path , "/ " ) === 0 ) {
561
- $ dirname = "/ " ;
562
- } else {
563
- $ dirname = false ;
564
- }
565
-
566
- if ($ dirname == ". " ) {
567
- $ dirname = false ;
568
- }
569
-
570
- return $ dirname ;
568
+ return dirname ($ path );
571
569
572
570
default :
573
571
return "unknown " ;
@@ -847,6 +845,7 @@ public function toExternalPath(string $internalPath): string
847
845
return $ externalPath ;
848
846
}
849
847
848
+ // Remove root path
850
849
if (substr ($ externalPath , 0 , strlen ($ this ->rootPath ())) == $ this ->rootPath ()) {
851
850
$ externalPath = substr ($ externalPath , strlen ($ this ->rootPath ()));
852
851
} else {
@@ -856,21 +855,22 @@ public function toExternalPath(string $internalPath): string
856
855
}
857
856
}
858
857
858
+ // If the internal path was the root path, set it to the dot slash notation
859
859
if (strlen ($ externalPath ) === 0 ) {
860
860
return $ this ->cleanPath ("./ " );
861
861
}
862
862
863
- if ($ externalPath [0 ] != ' / ' ) {
863
+ if ($ externalPath [0 ] != DIRECTORY_SEPARATOR ) {
864
864
return $ internalPath ;
865
865
}
866
866
867
867
$ nbrTurns = 0 ;
868
868
$ maxNbrTurns = count ($ this ->aliases );
869
- do {
870
- $ appliedAliasesNbr = 0 ;
869
+ $ appliedAliasesNbr = 0 ;
871
870
871
+ do {
872
872
foreach ($ this ->aliases as $ key => $ value ) {
873
- $ value = ' / ' . $ value ;
873
+ $ value = DIRECTORY_SEPARATOR . $ value ;
874
874
if (substr ($ externalPath , 0 , strlen ($ value )) == $ value ) {
875
875
$ externalPath = $ this ->makePath ($ key , substr ($ externalPath , strlen ($ value )));
876
876
$ appliedAliasesNbr ++;
@@ -880,6 +880,9 @@ public function toExternalPath(string $internalPath): string
880
880
$ nbrTurns ++;
881
881
} while ($ appliedAliasesNbr > 0 && $ nbrTurns <= $ maxNbrTurns );
882
882
883
+ if ($ appliedAliasesNbr == 0 && $ externalPath [0 ] == DIRECTORY_SEPARATOR )
884
+ $ externalPath = $ this ->makePath ( '. ' , $ externalPath );
885
+
883
886
return $ this ->cleanPath ($ externalPath );
884
887
}
885
888
@@ -924,7 +927,7 @@ public function toFileSystemPath(string $internalPath): string
924
927
$ nbrTurns ++;
925
928
} while ($ appliedAliasesNbr > 0 && $ nbrTurns <= $ maxNbrTurns );
926
929
927
- while (substr ($ externalPath , 0 , 1 ) == ' / ' || substr ($ externalPath , 0 , 2 ) == './ ' ) {
930
+ while (substr ($ externalPath , 0 , 1 ) == DIRECTORY_SEPARATOR || substr ($ externalPath , 0 , 2 ) == '. ' . DIRECTORY_SEPARATOR ) {
928
931
$ externalPath = substr ($ externalPath , 1 );
929
932
}
930
933
0 commit comments