From ed6b5569fda87c2251cd30a23b4db687f4f9f2ae Mon Sep 17 00:00:00 2001 From: "o.pinke" Date: Mon, 11 Mar 2024 15:47:48 +0100 Subject: [PATCH] new exceptions and handler for log writer file --- .../Exceptions/FileNotFoundException.php | 8 ++++ .../classes/Exceptions/RuntimeException.php | 8 ++++ conlite/classes/Log/LogWriterFile.php | 42 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 conlite/classes/Exceptions/FileNotFoundException.php create mode 100644 conlite/classes/Exceptions/RuntimeException.php diff --git a/conlite/classes/Exceptions/FileNotFoundException.php b/conlite/classes/Exceptions/FileNotFoundException.php new file mode 100644 index 0000000..bf27e24 --- /dev/null +++ b/conlite/classes/Exceptions/FileNotFoundException.php @@ -0,0 +1,8 @@ +createHandle(); + } + + /** + * @param string $message + * @param int $priority + * @return bool + */ + public function write($message, $priority): bool + { + return fwrite($this->handle, $message) != false; + } + + /** + * @throws Exception + * @throws FileNotFoundException + */ + protected function createHandle(): void + { + $destination = $this->getOption('destination'); + if ($destination == '') { + throw new Exception('No destination was specified.'); + } + + if (($this->handle = fopen($destination, 'a')) === false) { + throw new FileNotFoundException('Destination handle could not be created.'); + } + } } \ No newline at end of file