Skip to content

Commit

Permalink
Cleaning up Kohana_Config_Database: renamed columns for SQL compatibi…
Browse files Browse the repository at this point in the history
…lity, updated comments, added schema
  • Loading branch information
Woody Gilk committed Aug 7, 2009
1 parent 39984bf commit 7823997
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions classes/kohana/config/database.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
* File-based configuration loader.
* 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)
*
* @package Kohana
* @author Kohana Team
* @copyright (c) 2008-2009 Kohana Team
* @copyright (c) 2009 Kohana Team
* @license http://kohanaphp.com/license.html
*/
class Kohana_Config_Database extends Kohana_Config_Reader {
Expand All @@ -31,7 +38,7 @@ public function __construct(array $config = NULL)
/**
* Query the configuration table for all values for this group and
* unserialize each of the values.
*
*
* @param string group name
* @param array configuration array
* @return $this clone of the current object
Expand All @@ -41,15 +48,15 @@ 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('key', 'value')
$query = DB::select('config_key', 'config_value')
->from($this->_database_table)
->where('group', '=', $group)
->where('group_name', '=', $group)
->execute($this->_database_instance);

if (count($query) > 0)
{
// Unserialize the configuration values
$config = array_map('unserialize', $query->as_array('key', 'value'));
$config = array_map('unserialize', $query->as_array('config_key', 'config_value'));
}
}

Expand All @@ -69,17 +76,17 @@ public function offsetSet($key, $value)
if ( ! $this->offsetExists($key))
{
// Insert a new value
DB::insert($this->_database_table, array('group', 'key', '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('value', serialize($value))
->where('group', '=', $this->_configuration_group)
->where('key', '=', $key)
->value('config_value', serialize($value))
->where('group_name', '=', $this->_configuration_group)
->where('config_key', '=', $key)
->execute($this->_database_instance);
}

Expand Down

0 comments on commit 7823997

Please sign in to comment.