File tree Expand file tree Collapse file tree 4 files changed +60
-4
lines changed Expand file tree Collapse file tree 4 files changed +60
-4
lines changed Original file line number Diff line number Diff line change 2525use function is_array ;
2626use function is_dir ;
2727use function is_file ;
28- use function is_string ;
2928use function preg_match ;
3029use function str_ends_with ;
3130use function str_ireplace ;
@@ -51,12 +50,12 @@ abstract class FileSystem
5150 */
5251 public static function isAbsPath (string $ path ): bool
5352 {
54- if (!$ path || ! is_string ( $ path ) ) {
53+ if (!$ path ) {
5554 return false ;
5655 }
5756
5857 if (str_starts_with ($ path , '/ ' ) || // linux/mac
59- 1 === preg_match ('#^[a-z]:[\ /| \\\].+#i ' , $ path ) // windows
58+ 1 === preg_match ('#^[a-z]:[/| \\\].+#i ' , $ path ) // windows
6059 ) {
6160 return true ;
6261 }
Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ class IniParser extends AbstractParser
3939 * @param string $fileDir When the second param is true, this param is valid.
4040 *
4141 * @return array
42- * @throws InvalidArgumentException
4342 * @throws UnexpectedValueException
4443 */
4544 protected static function doParse (
Original file line number Diff line number Diff line change 99 */
1010class Path extends FileSystem
1111{
12+ /**
13+ * @param string $path
14+ *
15+ * @return bool
16+ */
17+ public static function isAbs (string $ path ): bool
18+ {
19+ return self ::isAbsPath ($ path );
20+ }
1221
22+ /**
23+ * @param string $path
24+ *
25+ * @return bool
26+ */
27+ public static function isAbsolute (string $ path ): bool
28+ {
29+ return self ::isAbsolutePath ($ path );
30+ }
31+
32+ /**
33+ * @param string $path
34+ *
35+ * @return string
36+ */
37+ public static function format (string $ path ): string
38+ {
39+ return self ::pathFormat ($ path );
40+ }
1341}
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Toolkit \FsUtilTest ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use Toolkit \FsUtil \Path ;
7+
8+ /**
9+ * class PathTest
10+ *
11+ * @author inhere
12+ */
13+ class PathTest extends TestCase
14+ {
15+ public function testPath_isAbs (): void
16+ {
17+ $ tests = [
18+ '/tmp ' ,
19+ 'C:/tmp ' ,
20+ 'C: \\tmp ' ,
21+ 'C:\tmp ' ,
22+ "C: \\tmp " ,
23+ ];
24+
25+ foreach ($ tests as $ case ) {
26+ $ this ->assertTrue (Path::isAbs ($ case ));
27+ $ this ->assertTrue (Path::isAbsolute ($ case ));
28+ }
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments