Class Config_Database_Writer

Config_Database_Writer

extends Kohana_Config_Database_Writer
extends Config_Database_Reader
extends Kohana_Config_Database_Reader

Implements: Kohana_Config_Writer | Kohana_Config_Source | Kohana_Config_Reader

Transparent extension for the Kohana_Config_Database_Writer class

package
Kohana/Database
category
Configuration
author
Kohana Team
copyright
(c) Kohana Team
license
https://koseven.ga/LICENSE.md


Information

This class is a transparent base class for Kohana_Config_Database_Writer

Properties

protected $_db_instance

Default value:
NULL

protected $_loaded_keys

Default value:
array(0) 

protected $_table_name

Default value:
string(6) "config"

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, ['group_name', 'config_key', 'config_value'])
		->values([$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(['config_value' => $config])
		->where('group_name', '=', $group)
		->where('config_key', '=', $key)
		->execute($this->_db_instance);

	return $this;
}

Do you want to contribute to Koseven?

We need YOUR help!

This project is open source. What does this mean? YOU can help:
  • Found a bug? Report it on Github
  • Need a feature? Add it Here
  • Want to help? Join the Forum
Go to Github