From 01d97bface9a38531d1fdb28a78adfeedc174a10 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sun, 28 Aug 2011 16:18:25 +0100 Subject: [PATCH] Add support for removing config settings --- source/lib/SihnonFramework/Config.class.php | 15 +++++++++++++++ .../SihnonFramework/Config/IUpdateable.class.php | 8 ++++++++ .../Config/Plugin/Database.class.php | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/source/lib/SihnonFramework/Config.class.php b/source/lib/SihnonFramework/Config.class.php index 1c5b71a..4e012c1 100644 --- a/source/lib/SihnonFramework/Config.class.php +++ b/source/lib/SihnonFramework/Config.class.php @@ -152,6 +152,21 @@ class SihnonFramework_Config { // Persist the setting into the backend return $this->backend->add($key, $type, $packed_value); } + + public function remove($key) { + if ( ! ($this->backend instanceof Sihnon_Config_IUpdateable)) { + throw new Sihnon_Exception_ReadOnlyConfigBackend(); + } + if (!isset($this->settings[$key])) { + throw new Sihnon_Exception_UnknownSetting($key); + } + + // Remove the setting for this run + unset($this->settings[$key]); + + // Persist the change into the backend + return $this->backend->remove($key); + } }; diff --git a/source/lib/SihnonFramework/Config/IUpdateable.class.php b/source/lib/SihnonFramework/Config/IUpdateable.class.php index 1aa5237..76c1b60 100644 --- a/source/lib/SihnonFramework/Config/IUpdateable.class.php +++ b/source/lib/SihnonFramework/Config/IUpdateable.class.php @@ -21,6 +21,14 @@ interface SihnonFramework_Config_IUpdateable { */ public function add($key, $type, $value); + /** + * + * Remove a setting + * @param string $key + * @return bool + */ + public function remove($key); + } ?> \ No newline at end of file diff --git a/source/lib/SihnonFramework/Config/Plugin/Database.class.php b/source/lib/SihnonFramework/Config/Plugin/Database.class.php index a5dd2de..dc98509 100644 --- a/source/lib/SihnonFramework/Config/Plugin/Database.class.php +++ b/source/lib/SihnonFramework/Config/Plugin/Database.class.php @@ -43,6 +43,12 @@ class SihnonFramework_Config_Plugin_Database extends Sihnon_PluginBase implement )); } + public function remove($key) { + return $this->database->update("DELETE FROM `{$this->table}` WHERE `name`=:name LIMIT 1", array( + array('name' => 'name', 'value' => $key, 'type' => PDO::PARAM_STR), + )); + } + } ?> \ No newline at end of file