Implements: Kohana_Config_Writer | Kohana_Config_Source | Kohana_Config_Reader
Transparent extension for the Kohana_Config_Database_Writer class
Class declared in MODPATH/database/classes/Config/Database/Writer.php on line 12.
$_db_instanceNULL
$_loaded_keysarray(0)
$_table_namestring(6) "config"
Tries to load the specificed configuration group
Returns FALSE if group does not exist or an array if it does
string
$group
required - Configuration groupboolean|array
public function load($group)
{
$config = parent::load($group);
if ($config !== FALSE)
{
$this->_loaded_keys[$group] = array_combine(array_keys($config), array_keys($config));
}
return $config;
}
Writes the passed config for $group
Returns chainable instance on success or throws Kohana_Config_Exception on failure
string
$group
required - The config groupstring
$key
required - The config key to write toarray
$config
required - The configuration to writeboolean
public function write($group, $key, $config)
{
$config = serialize($config);
// Check to see if we've loaded the config from the table already
if (isset($this->_loaded_keys[$group][$key]))
{
$this->_update($group, $key, $config);
}
else
{
// Attempt to run an insert query
// This may fail if the config key already exists in the table
// and we don't know about it
try
{
$this->_insert($group, $key, $config);
}
catch (Database_Exception $e)
{
// Attempt to run an update instead
$this->_update($group, $key, $config);
}
}
return TRUE;
}
Constructs the database reader object
array
$config
= NULL - Configuration for the readerpublic function __construct(array $config = NULL)
{
if (isset($config['instance']))
{
$this->_db_instance = $config['instance'];
}
elseif ($this->_db_instance === NULL)
{
$this->_db_instance = Database::$default;
}
if (isset($config['table_name']))
{
$this->_table_name = $config['table_name'];
}
}
Insert the config values into the table
string
$group
required - The config groupstring
$key
required - The config key to write toarray
$config
required - The serialized configuration to writeboolean
protected function _insert($group, $key, $config)
{
DB::insert($this->_table_name, array('group_name', 'config_key', 'config_value'))
->values(array($group, $key, $config))
->execute($this->_db_instance);
return $this;
}
Update the config values in the table
string
$group
required - The config groupstring
$key
required - The config key to write toarray
$config
required - The serialized configuration to writeboolean
protected function _update($group, $key, $config)
{
DB::update($this->_table_name)
->set(array('config_value' => $config))
->where('group_name', '=', $group)
->where('config_key', '=', $key)
->execute($this->_db_instance);
return $this;
}