diff options
Diffstat (limited to '_classes/Comment.php')
-rw-r--r-- | _classes/Comment.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/_classes/Comment.php b/_classes/Comment.php new file mode 100644 index 0000000..6d4fd48 --- /dev/null +++ b/_classes/Comment.php @@ -0,0 +1,26 @@ +<?php + + +class Comment +{ + function __construct(string $comment, string $postURL, string $username = 'Anonymous') + { + $this->timestamp = date('Y-m-d H:i:s'); + $this->username = $username; + $this->comment = $comment; + $this->postURL = $postURL; + } + + function saveComment(string $fileName) + { + if (file_exists($fileName)) { + $sourceData = file_get_contents($fileName); + $tempArray = json_decode($sourceData); + array_push($tempArray, $this); + $jsonData = json_encode($tempArray, JSON_PRETTY_PRINT); + file_put_contents($fileName, $jsonData); + } else { + die('Error: The ' . $fileName . ' file does not exist.'); + } + } +}
\ No newline at end of file |