Add write support to Config backends with add/set methods
This commit is contained in:
26
source/lib/SihnonFramework/Config/IUpdateable.class.php
Normal file
26
source/lib/SihnonFramework/Config/IUpdateable.class.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
interface SihnonFramework_Config_IUpdateable {
|
||||
|
||||
/**
|
||||
*
|
||||
* Change the value of a setting
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function set($key, $value);
|
||||
|
||||
/**
|
||||
*
|
||||
* Add a new setting
|
||||
* @param string $key
|
||||
* @param string $type
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function add($key, $type, $value);
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class SihnonFramework_Config_Plugin_Database extends Sihnon_PluginBase implements Sihnon_Config_IPlugin {
|
||||
class SihnonFramework_Config_Plugin_Database extends Sihnon_PluginBase implements Sihnon_Config_IPlugin, Sihnon_Config_IUpdateable {
|
||||
|
||||
/**
|
||||
* Name of this plugin
|
||||
@@ -28,6 +28,21 @@ class SihnonFramework_Config_Plugin_Database extends Sihnon_PluginBase implement
|
||||
throw new Sihnon_Exception_NotImplemented();
|
||||
}
|
||||
|
||||
public function set($key, $value) {
|
||||
return $this->database->update("UPDATE `{$this->table}` SET `value`=:value WHERE `name`=:name", array(
|
||||
array('name' => 'name', 'value' => $key, 'type' => PDO::PARAM_STR),
|
||||
array('name' => 'value', 'value' => $value, 'type' => PDO::PARAM_STR),
|
||||
));
|
||||
}
|
||||
|
||||
public function add($key, $type, $value) {
|
||||
return $this->database->insert("INSERT INTO `{$this->table}` (`name`,`value`,`type`) VALUES(:name,:value,:type)", array(
|
||||
array('name' => 'name', 'value' => $key, 'type' => PDO::PARAM_STR),
|
||||
array('name' => 'value', 'value' => $value, 'type' => PDO::PARAM_STR),
|
||||
array('name' => 'type', 'value' => $type, 'type' => PDO::PARAM_STR),
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user