Add support for removing config settings
This commit is contained in:
@@ -153,6 +153,21 @@ class SihnonFramework_Config {
|
|||||||
return $this->backend->add($key, $type, $packed_value);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ interface SihnonFramework_Config_IUpdateable {
|
|||||||
*/
|
*/
|
||||||
public function add($key, $type, $value);
|
public function add($key, $type, $value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Remove a setting
|
||||||
|
* @param string $key
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function remove($key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -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),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user