summaryrefslogtreecommitdiff
path: root/src/Client/Filesystem/CreateDirectory.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client/Filesystem/CreateDirectory.php')
-rw-r--r--src/Client/Filesystem/CreateDirectory.php49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Client/Filesystem/CreateDirectory.php b/src/Client/Filesystem/CreateDirectory.php
new file mode 100644
index 0000000..2621169
--- /dev/null
+++ b/src/Client/Filesystem/CreateDirectory.php
@@ -0,0 +1,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);
+ }
+}