Modules
Kohana_Config_Database
extends Kohana_Config_Reader
extends ArrayObject
Database-based configuration loader.
Schema for configuration table:
group_name varchar(128)
config_key varchar(128)
config_value text
primary key (group_name, config_key)
Class declared in MODPATH/database/classes/kohana/config/database.php on line 18.
Constants
Methods
- __construct()
- load()
- offsetSet()
- __toString()
- as_array()
- get()
- set()
- append()
- asort()
- count()
- exchangeArray()
- getArrayCopy()
- getFlags()
- getIterator()
- getIteratorClass()
- ksort()
- natcasesort()
- natsort()
- offsetExists()
- offsetGet()
- offsetUnset()
- serialize()
- setFlags()
- setIteratorClass()
- uasort()
- uksort()
- unserialize()
Constants
STD_PROP_LIST
integer 1
ARRAY_AS_PROPS
integer 2
Properties
protected
string$_configuration_groupConfiguration group name
protected
$_database_instanceprotected
$_database_table
Methods
public __construct( ) (defined in Kohana_Config_Database)
Loads an empty array as the initial configuration and enables array keys to be used as properties.
Return Values
void
Source Code
public function __construct(array $config = NULL)
{
if (isset($config['instance']))
{
$this->_database_instance = $config['instance'];
}
if (isset($config['table']))
{
$this->_database_table = $config['table'];
}
parent::__construct();
}
public load( string $group [, array $config = NULL ] ) (defined in Kohana_Config_Database)
Query the configuration table for all values for this group and unserialize each of the values.
Parameters
-
string$group required - Group name -
array$config = NULL - Configuration array
Return Values
$this- Clone of the current object
Source Code
public function load($group, array $config = NULL)
{
if ($config === NULL AND $group !== 'database')
{
// Load all of the configuration values for this group
$query = DB::select('config_key', 'config_value')
->from($this->_database_table)
->where('group_name', '=', $group)
->execute($this->_database_instance);
if (count($query) > 0)
{
// Unserialize the configuration values
$config = array_map('unserialize', $query->as_array('config_key', 'config_value'));
}
}
return parent::load($group, $config);
}
public offsetSet( string $key , mixed $value ) (defined in Kohana_Config_Database)
Overload setting offsets to insert or update the database values as changes occur.
Parameters
-
string$key required - Array key -
mixed$value required - New value
Return Values
mixed
Source Code
public function offsetSet($key, $value)
{
if ( ! $this->offsetExists($key))
{
// Insert a new value
DB::insert($this->_database_table, array('group_name', 'config_key', 'config_value'))
->values(array($this->_configuration_group, $key, serialize($value)))
->execute($this->_database_instance);
}
elseif ($this->offsetGet($key) !== $value)
{
// Update the value
DB::update($this->_database_table)
->value('config_value', serialize($value))
->where('group_name', '=', $this->_configuration_group)
->where('config_key', '=', $key)
->execute($this->_database_instance);
}
return parent::offsetSet($key, $value);
}
public __toString( ) (defined in Kohana_Config_Reader)
Return the current group in serialized form.
echo $config;
Return Values
string
Source Code
public function __toString()
{
return serialize($this->getArrayCopy());
}
public as_array( ) (defined in Kohana_Config_Reader)
Return the raw array that is being used for this object.
$array = $config->as_array();
Return Values
array
Source Code
public function as_array()
{
return $this->getArrayCopy();
}
public get( string $key [, mixed $default = NULL ] ) (defined in Kohana_Config_Reader)
Get a variable from the configuration or return the default value.
$value = $config->get($key);
Parameters
-
string$key required - Array key -
mixed$default = NULL - Default value
Return Values
mixed
Source Code
public function get($key, $default = NULL)
{
return $this->offsetExists($key) ? $this->offsetGet($key) : $default;
}
public set( string $key , mixed $value ) (defined in Kohana_Config_Reader)
Sets a value in the configuration array.
$config->set($key, $new_value);
Parameters
-
string$key required - Array key -
mixed$value required - Array value
Return Values
$this
Source Code
public function set($key, $value)
{
$this->offsetSet($key, $value);
return $this;
}