summaryrefslogtreecommitdiff
path: root/src/Filesystem
diff options
context:
space:
mode:
Diffstat (limited to 'src/Filesystem')
-rw-r--r--src/Filesystem/Create.php45
-rw-r--r--src/Filesystem/CreateDirectory.php16
-rw-r--r--src/Filesystem/CreateFile.php17
3 files changed, 20 insertions, 58 deletions
diff --git a/src/Filesystem/Create.php b/src/Filesystem/Create.php
deleted file mode 100644
index 45b09fd..0000000
--- a/src/Filesystem/Create.php
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-
-namespace App\Filesystem;
-
-
-/**
- * Base class for creating filesystem things
- *
- * @author Phil Burton <phil@d3r.com>
- */
-abstract class Create
-{
- /**
- * Filename to create
- *
- * @var string
- * @author Phil Burton <phil@d3r.com>
- */
- protected $filename;
-
- /**
- * Thing we're creating, used for messages
- *
- * @var string
- * @author Phil Burton <phil@d3r.com>
- */
- protected $thing;
-
- /**
- * Set filename on object and check we can wirte to the Directory
- *
- * @param string $filename
- * @author Phil Burton <phil@d3r.com>
- */
- 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
index 2af53d7..c74cba4 100644
--- a/src/Filesystem/CreateDirectory.php
+++ b/src/Filesystem/CreateDirectory.php
@@ -2,14 +2,12 @@
namespace App\Filesystem;
-use App\Filesystem\Create;
-
/**
* Class to create a new directory
*
* @author Phil Burton <phil@d3r.com>
*/
-class CreateDirectory extends Create
+class CreateDirectory
{
/**
* Thing we're creating
@@ -18,6 +16,8 @@ class CreateDirectory extends Create
*/
protected $thing = "directory";
+ protected $filename;
+
/**
* Check if the directory already exists
*
@@ -26,7 +26,11 @@ class CreateDirectory extends Create
*/
public function __construct(string $filename)
{
- parent::__construct($filename);
+ $this->filename = $filename;
+
+ if (!is_writable(dirname($filename))) {
+ throw new \Exception('Cannot create ' . $this->thing . ' at: ' . $filename);
+ }
if (file_exists($filename)) {
throw new \Exception('Directory already exists at: ' . $filename);
@@ -38,8 +42,8 @@ class CreateDirectory extends Create
*
* @author Phil Burton <phil@d3r.com>
*/
- public function excecute()
+ public function execute()
{
- echo "execute";
+ mkdir($this->filename);
}
}
diff --git a/src/Filesystem/CreateFile.php b/src/Filesystem/CreateFile.php
index 7fed65c..08ba0db 100644
--- a/src/Filesystem/CreateFile.php
+++ b/src/Filesystem/CreateFile.php
@@ -2,15 +2,12 @@
namespace App\Filesystem;
-use App\Filesystem\Create;
-
/**
* Class to create a new file
*
- * @param string $filename [description]
* @author Phil Burton <phil@d3r.com>
*/
-class CreateFile extends Create
+class CreateFile
{
/**
* Thing we're creating
@@ -19,6 +16,8 @@ class CreateFile extends Create
*/
protected $thing = "file";
+ protected $filename;
+
/**
* Check if the file already exists
*
@@ -27,7 +26,11 @@ class CreateFile extends Create
*/
public function __construct(string $filename)
{
- parent::__construct($filename);
+ $this->filename = $filename;
+
+ if (!is_writable(dirname($filename))) {
+ throw new \Exception('Cannot create ' . $this->thing . ' at: ' . $filename);
+ }
if (file_exists($filename)) {
throw new \Exception('File already exists at: ' . $filename);
@@ -39,8 +42,8 @@ class CreateFile extends Create
*
* @author Phil Burton <phil@d3r.com>
*/
- public function excecute()
+ public function execute()
{
- echo "execute";
+ touch($this->filename);
}
}