Skip to content

Commit

Permalink
Added path utility to ensure a path exists and to get the path from a…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
passioneight committed Dec 15, 2021
1 parent a63ebde commit 5f52e43
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Service/Utility/PathUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,28 @@ public static function addLeadingSlash(string $path)
{
return DIRECTORY_SEPARATOR . $path;
}

/**
* @param string $path
* @param int $mode
* @param bool $recursive
* @return bool
*/
public static function ensurePath(string $path, int $mode = 0777, bool $recursive = true)
{
if (!is_dir($path)) {
return mkdir($path, $mode, $recursive);
}

return true;
}

/**
* @param string $file
* @return false|string
*/
public static function getPathFromFile(string $file)
{
return StringUtility::removeFromEnd(DIRECTORY_SEPARATOR, $file, true);
}
}

0 comments on commit 5f52e43

Please sign in to comment.