From 005f95bda30cb6a5a32301f48be777109e2d4b0e Mon Sep 17 00:00:00 2001 From: James Newell Date: Sat, 4 Jan 2014 22:36:18 +1100 Subject: [PATCH] added methods to read and write file content --- src/deit/filesystem/Filesystem.php | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/deit/filesystem/Filesystem.php b/src/deit/filesystem/Filesystem.php index 1867d31..4756fc6 100644 --- a/src/deit/filesystem/Filesystem.php +++ b/src/deit/filesystem/Filesystem.php @@ -259,5 +259,36 @@ public function remove($path) { return $this; } + /** + * Gets the file content + * @param string $file + * @return string + * @throws + */ + public function getContent($file) { + + if (($content = file_get_contents($file)) === false) { + throw new \Exception('Unable to get file content.'); + } + + return $content; + } + + /** + * Sets the file content + * @param string $file + * @param string $content + * @return $this + * @throws + */ + public function setContent($file, $content) { + + if (($content = file_put_contents($file, $content)) === false) { + throw new \Exception('Unable to set file content.'); + } + + return $this; + } + } \ No newline at end of file