Modules

Config_Database
extends Kohana_Config_Database
extends Kohana_Config_Database_Writer
extends Config_Database_Reader
extends Kohana_Config_Database_Reader

Implements: Kohana_Config_Reader | Kohana_Config_Source | Kohana_Config_Writer

Transparent extension for the Kohana_Config_Database class

package
Kohana/Database
category
Configuration
author
Kohana Team
copyright
© 2012 Kohana Team
license
http://kohanaframework.org/license

Class declared in MODPATH/database/classes/config/database.php on line 12.

Properties

protected $_db_instance

protected $_loaded_keys

protected $_table_name

Methods

public load( string $group ) (defined in Kohana_Config_Database_Writer)

Tries to load the specificed configuration group

Returns FALSE if group does not exist or an array if it does

Parameters

  • string $group required - Configuration group

Return Values

  • boolean|array

Source Code

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;
}

public write( string $group , string $key , array $config ) (defined in Kohana_Config_Database_Writer)

Writes the passed config for $group

Returns chainable instance on success or throws Kohana_Config_Exception on failure

Parameters

  • string $group required - The config group
  • string $key required - The config key to write to
  • array $config required - The configuration to write

Return Values

  • boolean

Source Code

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;
}

public __construct( [ array $config = NULL ] ) (defined in Kohana_Config_Database_Reader)

Constructs the database reader object

Parameters

  • array $config = NULL - Configuration for the reader

Source Code

public 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'];
    }
}

protected _insert( string $group , string $key , array $config ) (defined in Kohana_Config_Database_Writer)

Insert the config values into the table

Parameters

  • string $group required - The config group
  • string $key required - The config key to write to
  • array $config required - The serialized configuration to write

Return Values

  • boolean

Source Code

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;
}

protected _update( string $group , string $key , array $config ) (defined in Kohana_Config_Database_Writer)

Update the config values in the table

Parameters

  • string $group required - The config group
  • string $key required - The config key to write to
  • array $config required - The serialized configuration to write

Return Values

  • boolean

Source Code

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;
}