diff options
author | Phil Burton <phil@pgburton.com> | 2017-08-22 10:10:29 +0100 |
---|---|---|
committer | Phil Burton <phil@pgburton.com> | 2017-08-22 10:10:29 +0100 |
commit | 7b1e62d0cbc3519c469b2afd4da712125707de66 (patch) | |
tree | 06ee38c18849f9b0c85c2eb82bded824e2ff34e6 /src/Filesystem/CreateFile.php | |
parent | a4170353515c254ab7404117e7d9b3f15887214a (diff) | |
parent | 47b154758e789e75ec597d88540cdb7f4e352225 (diff) |
Merge branch 'master' of www.blatech.co.uk:FBeans/dipper
Diffstat (limited to 'src/Filesystem/CreateFile.php')
-rw-r--r-- | src/Filesystem/CreateFile.php | 13 |
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); + } } } |