-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task: introduce file utility to create folders (#456)
- Loading branch information
1 parent
fd57aaf
commit cef8357
Showing
3 changed files
with
29 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Photobooth\Utility; | ||
|
||
class FileUtility | ||
{ | ||
public const DIRECTORY_PERMISSIONS = 0755; | ||
|
||
public static function createDirectory(string $directory): void | ||
{ | ||
if (!file_exists($directory) && !is_dir($directory)) { | ||
if (!mkdir($directory, self::DIRECTORY_PERMISSIONS, true)) { | ||
throw new \Exception('Failed to create directory: ' . $directory); | ||
} | ||
} elseif (!is_writable($directory)) { | ||
if (!chmod($directory, self::DIRECTORY_PERMISSIONS)) { | ||
throw new \Exception('Failed to change permissions of directory: ' . $directory); | ||
} | ||
} | ||
} | ||
} |