Skip to content

Commit

Permalink
refactor(util.path): get relative path support multiple paths
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Aug 24, 2018
1 parent 5d66504 commit 3d89fd8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Util/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,28 @@ class Path
public function isAbsolute(string $path): bool
{
if (\DIRECTORY_SEPARATOR === '\\') {
return strpos($path, ':') === 1;
return \strpos($path, ':') === 1;
}

return isset($path[0]) && $path[0] === '/';
}

public function getRelativePath($fullPath, $basePath): string
public function getRelativePath(string $fullPath, string ...$basePaths): string
{
if (strpos($fullPath, $basePath) === 0) {
return substr($fullPath, strlen($basePath));
foreach ($basePaths as $basePath) {
if (\strpos($fullPath, $basePath) === 0) {
return \substr($fullPath, \strlen($basePath));
}
}

// Hmm!
return $fullPath;
}

public function ensureDir(string $dir): bool
public function ensureDir(string $dir, $mode = 0777): bool
{
if (!\is_dir($dir)) {
return \mkdir($dir, 0777, true);
return \mkdir($dir, $mode, true);
}

return true;
Expand Down

0 comments on commit 3d89fd8

Please sign in to comment.