Total Complexity | 4 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class TemporaryDirectories |
||
8 | { |
||
9 | /** |
||
10 | * Root of the temporary directories. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | private $root; |
||
15 | |||
16 | /** |
||
17 | * Array of all directories |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | private $directories = []; |
||
22 | |||
23 | /** |
||
24 | * Sets the root and removes the trailing slash. |
||
25 | * |
||
26 | * @param string $root |
||
27 | */ |
||
28 | public function __construct(string $root) |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Returns the full path a of new temporary directory. |
||
35 | * |
||
36 | * @return string |
||
37 | */ |
||
38 | public function create(): string |
||
39 | { |
||
40 | $directory = $this->root . '/' . bin2hex(random_bytes(8)); |
||
41 | |||
42 | mkdir($directory, 0777, true); |
||
43 | |||
44 | return $this->directories[] = $directory; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Loop through all directories and delete them. |
||
49 | */ |
||
50 | public function deleteAll(): void |
||
59 | } |
||
60 | } |
||
61 |