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