@@ 16-29 (lines=14) @@ | ||
13 | * |
|
14 | * @throws \RuntimeException |
|
15 | */ |
|
16 | public static function ensure($path, $mode = 0777) { |
|
17 | if (is_dir($path)) { |
|
18 | return; |
|
19 | } |
|
20 | if (@mkdir($path, $mode, true)) { |
|
21 | return; |
|
22 | } |
|
23 | throw new \RuntimeException(sprintf("Unable to create folder '%s': %s", $path, error_get_last()['message'])); |
|
24 | } |
|
25 | ||
26 | /** |
|
27 | * Delete a directory and all of its contents recursively. |
|
28 | * |
|
29 | * @param string $path Path of folder to delete |
|
30 | * |
|
31 | * @throws \RuntimeException Thrown when something could not be deleted. |
|
32 | */ |
|
@@ 33-46 (lines=14) @@ | ||
30 | * |
|
31 | * @throws \RuntimeException Thrown when something could not be deleted. |
|
32 | */ |
|
33 | public static function delete($path) { |
|
34 | if (!is_dir($path)) { |
|
35 | return; |
|
36 | } |
|
37 | self::deleteContents($path); |
|
38 | if (@rmdir($path) === false) { |
|
39 | throw new \RuntimeException(sprintf("Unable to delete folder '%s': %s", $path, error_get_last()['message'])); |
|
40 | } |
|
41 | } |
|
42 | ||
43 | /** |
|
44 | * deleteContents of a folder recursively, but not the folder itself. |
|
45 | * |
|
46 | * On Windows systems this will try to remove the read-only attribute if needed. |
|
47 | * |
|
48 | * @param string $path Path of folder whose contents will be deleted |
|
49 | * |