Skip to content

Commit 8cb2d1b

Browse files
authored
Update PathUtility.php
1 parent 0fe76c6 commit 8cb2d1b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/Utility/PathUtility.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,29 @@ public static function fixFilePath(string $path): string
8686
{
8787
return str_replace(['\\', '//'], '/', $path);
8888
}
89+
90+
public static function resolveFilePath(string $filePath): string {
91+
if (self::isUrl($filePath)) {
92+
return $filePath;
93+
}
94+
95+
if (!self::isAbsolutePath($filePath)) {
96+
$filePath = self::getAbsolutePath($filePath);
97+
}
98+
99+
if (file_exists($filePath)) {
100+
return $filePath;
101+
}
102+
103+
$altPath1 = $_SERVER['DOCUMENT_ROOT'] . $filePath;
104+
$altPath2 = $_SERVER['DOCUMENT_ROOT'] . '/' . $filePath;
105+
106+
if (file_exists($altPath1)) {
107+
return $altPath1;
108+
} elseif (file_exists($altPath2)) {
109+
return $altPath2;
110+
}
111+
112+
throw new Exception('File not found: ' . $filePath);
113+
}
89114
}

0 commit comments

Comments
 (0)