From 882214d6eabb147d82a3df436fe5741e35b84484 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Wed, 27 Mar 2019 15:25:08 +0100 Subject: [PATCH] More over engineering. TBH at this point I think I need a DI container. --- src/Configuration.php | 5 ----- src/ReadableState.php | 13 +++++++++++++ src/State.php | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/ReadableState.php create mode 100644 src/State.php diff --git a/src/Configuration.php b/src/Configuration.php index a10434e..4f09bee 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -60,9 +60,4 @@ class Configuration { return $this->stateFile; } - - public function isOpen(): bool - { - return file_exists($this->stateFile); - } } diff --git a/src/ReadableState.php b/src/ReadableState.php new file mode 100644 index 0000000..0c5450b --- /dev/null +++ b/src/ReadableState.php @@ -0,0 +1,13 @@ +config = $config; + } + + /** + * Check whether the FooBar is open + * + * @return bool true if the FooBar is open. + */ + public function isOpen(): bool + { + return file_exists($this->config->stateFile()); + } + + /** + * Toggle the current state of the FooBar. + * + * @return bool the new state of the FooBar. + */ + public function toggle(): bool + { + if ($this->isOpen()) { + unlink($this->config->stateFile()); + return false; + } else { + touch($this->config->stateFile()); + return true; + } + } +}