Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Dec 12, 2024
1 parent cb6fade commit 634e80d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,21 @@ function refresh_router_lookups(Router $router): void
*/
function transform_realpath_to_relative(string $path, ?string $workingPath = null, string $prefix = ''): string
{
$separator = DIRECTORY_SEPARATOR;

if (! \is_null($workingPath)) {
return str_replace(rtrim($workingPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR, $prefix.DIRECTORY_SEPARATOR, $path);
return str_replace(rtrim($workingPath, $separator).$separator, $prefix.$separator, $path);
}

$laravelPath = base_path();
$workbenchPath = workbench_path();
$packagePath = package_path();

return match (true) {
str_starts_with($path, $laravelPath) => str_replace("{$laravelPath}/", '@laravel/', $path),
str_starts_with($path, $workbenchPath) => str_replace("{$workbenchPath}/", '@workbench/', $path),
str_starts_with($path, $packagePath) => str_replace("{$packagePath}/", './', $path),
! empty($prefix) => implode(DIRECTORY_SEPARATOR, [$prefix, ltrim($path, DIRECTORY_SEPARATOR)]),
str_starts_with($path, $laravelPath) => str_replace($laravelPath.$separator, '@laravel'.$separator, $path),
str_starts_with($path, $workbenchPath) => str_replace($workbenchPath.$separator, '@workbench'.$separator, $path),
str_starts_with($path, $packagePath) => str_replace($packagePath.$separator, '.'.$separator, $path),
! empty($prefix) => implode($separator, [$prefix, ltrim($path, $separator)]),
default => $path,
};
}
Expand Down

0 comments on commit 634e80d

Please sign in to comment.