blob: 26211698dd2582c8aa3e4e8d7b86a0ea16a81665 (
plain)
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
44
45
46
47
48
49
|
<?php
namespace App\Filesystem;
use App\Task\TaskInterface;
/**
* Class to create a new directory
*
* @author Phil Burton <phil@d3r.com>
*/
class CreateDirectory implements TaskInterface
{
/**
* Directory to create
*
* @var string
*/
protected $directory;
/**
* Check if the directory already exists
*
* @param string $filename
* @author Phil Burton <phil@d3r.com>
*/
public function __construct(string $directory)
{
$this->directory = $directory;
if (!is_writable(dirname($directory))) {
throw new \Exception('Cannot create directory at: ' . $directory);
}
if (file_exists($directory)) {
throw new \Exception('Directory already exists at: ' . $directory);
}
}
/**
* Create the new directory
*
* @author Phil Burton <phil@d3r.com>
*/
public function execute()
{
mkdir($this->directory);
}
}
|