diff options
Diffstat (limited to 'src/Filesystem')
-rw-r--r-- | src/Filesystem/Create.php | 20 | ||||
-rw-r--r-- | src/Filesystem/CreateDirectory.php | 25 | ||||
-rw-r--r-- | src/Filesystem/CreateFile.php | 25 |
3 files changed, 70 insertions, 0 deletions
diff --git a/src/Filesystem/Create.php b/src/Filesystem/Create.php new file mode 100644 index 0000000..a1891db --- /dev/null +++ b/src/Filesystem/Create.php @@ -0,0 +1,20 @@ +<?php + +namespace App\Filesystem; + +abstract class Create +{ + protected $filename; + protected $thing; + + public function __construct(string $filename) + { + $this->filename = $filename; + + if (!is_writable(dirname($filename))) { + throw new \Exception('Cannot create ' . $this->thing . ' at: ' . $filename); + } + } + + abstract public function excecute(); +} diff --git a/src/Filesystem/CreateDirectory.php b/src/Filesystem/CreateDirectory.php new file mode 100644 index 0000000..0c45c6c --- /dev/null +++ b/src/Filesystem/CreateDirectory.php @@ -0,0 +1,25 @@ +<?php + +namespace App\Filesystem; + +use App\Filesystem\Create; + +class CreateDirectory extends Create +{ + protected $filename; + protected $thing = "directory"; + + public function __construct(string $filename) + { + parent::__construct($filename); + + if (file_exists($filename)) { + throw new \Exception('Directory already exists at: ' . $filename); + } + } + + public function excecute() + { + echo "execute"; + } +} diff --git a/src/Filesystem/CreateFile.php b/src/Filesystem/CreateFile.php new file mode 100644 index 0000000..f41d4b9 --- /dev/null +++ b/src/Filesystem/CreateFile.php @@ -0,0 +1,25 @@ +<?php + +namespace App\Filesystem; + +use App\Filesystem\Create; + +class CreateFile extends Create +{ + protected $filename; + protected $thing = "file"; + + public function __construct(string $filename) + { + parent::__construct($filename); + + if (file_exists($filename)) { + throw new \Exception('File already exists at: ' . $filename); + } + } + + public function excecute() + { + echo "execute"; + } +} |