summaryrefslogtreecommitdiff
path: root/src/Filesystem/CreateFile.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Filesystem/CreateFile.php')
-rw-r--r--src/Filesystem/CreateFile.php13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/Filesystem/CreateFile.php b/src/Filesystem/CreateFile.php
index 08ba0db..93c66a6 100644
--- a/src/Filesystem/CreateFile.php
+++ b/src/Filesystem/CreateFile.php
@@ -18,16 +18,22 @@ class CreateFile
protected $filename;
+ protected $contents;
+
/**
* Check if the file already exists
*
* @param string $filename
* @author Phil Burton <phil@d3r.com>
*/
- public function __construct(string $filename)
+ public function __construct(string $filename, $contents = false)
{
$this->filename = $filename;
+ if ($contents) {
+ $this->contents = $contents;
+ }
+
if (!is_writable(dirname($filename))) {
throw new \Exception('Cannot create ' . $this->thing . ' at: ' . $filename);
}
@@ -45,5 +51,10 @@ class CreateFile
public function execute()
{
touch($this->filename);
+
+ $contents = $this->contents;
+ if ($contents) {
+ file_put_contents($this->filename, $contents);
+ }
}
}