From 62146c4027e48cfbdb4f518de137de8430392e24 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Sun, 18 Feb 2018 22:29:36 +0000 Subject: Split client and manager --- src/Client/Filesystem/CreateDirectory.php | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/Client/Filesystem/CreateDirectory.php (limited to 'src/Client/Filesystem/CreateDirectory.php') 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 @@ + + */ +class CreateDirectory implements TaskInterface +{ + /** + * Directory to create + * + * @var string + */ + protected $directory; + + /** + * Check if the directory already exists + * + * @param string $filename + * @author Phil Burton + */ + 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 + */ + public function execute() + { + mkdir($this->directory); + } +} -- cgit v1.2.3