-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathInteractsWithDirectories.php
43 lines (38 loc) · 1.14 KB
/
InteractsWithDirectories.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
declare(strict_types=1);
namespace Hyde\Framework\Concerns;
/**
* @see \Hyde\Framework\Testing\Unit\InteractsWithDirectoriesConcernTest
*/
trait InteractsWithDirectories
{
/**
* Ensure the supplied directory exist by creating it if it does not.
*
* @param string $directory absolute file path to the directory
*/
public static function needsDirectory(string $directory): void
{
if (! file_exists($directory)) {
mkdir($directory, recursive: true);
}
}
/**
* Ensure the supplied directories exist by creating them if they don't.
*
* @param array $directories array with absolute file paths to the directories
*/
public static function needsDirectories(array $directories): void
{
foreach ($directories as $directory) {
static::needsDirectory($directory);
}
}
/**
* Ensure the supplied file's parent directory exists by creating it if it does not.
*/
public static function needsParentDirectory(string $file, int $levels = 1): void
{
static::needsDirectory(dirname($file, $levels));
}
}