Modules

Config
extends Kohana_Config

Wrapper for configuration arrays. Multiple configuration readers can be attached to allow loading configuration from files, database, etc.

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

Class declared in SYSPATH/classes/config.php on line 3.

Constants

  • None

Properties

Properties

protected static Kohana_Config $_instance

Singleton static instance

object Config()

protected array $_readers

Configuration readers

Methods

public attach( Config_Reader $reader [, boolean $first = bool TRUE ] ) (defined in Kohana_Config)

Attach a configuration reader. By default, the reader will be added as the first used reader. However, if the reader should be used only when all other readers fail, use FALSE for the second parameter.

$config->attach($reader);        // Try first
$config->attach($reader, FALSE); // Try last

Parameters

  • Config_Reader $reader required - Config_Reader instance
  • boolean $first = bool TRUE - Add the reader as the first used object

Return Values

  • $this

Source Code

public function attach(Config_Reader $reader, $first = TRUE)
{
	if ($first === TRUE)
	{
		// Place the log reader at the top of the stack
		array_unshift($this->_readers, $reader);
	}
	else
	{
		// Place the reader at the bottom of the stack
		$this->_readers[] = $reader;
	}

	return $this;
}

public copy( string $group ) (defined in Kohana_Config)

Copy one configuration group to all of the other readers.

$config->copy($name);

Parameters

  • string $group required - Configuration group name

Return Values

  • $this

Source Code

public function copy($group)
{
	// Load the configuration group
	$config = $this->load($group);

	foreach ($this->_readers as $reader)
	{
		if ($config instanceof $reader)
		{
			// Do not copy the config to the same group
			continue;
		}

		// Load the configuration object
		$object = $reader->load($group, array());

		foreach ($config as $key => $value)
		{
			// Copy each value in the config
			$object->offsetSet($key, $value);
		}
	}

	return $this;
}

public detach( Config_Reader $reader ) (defined in Kohana_Config)

Detach a configuration reader.

$config->detach($reader);

Parameters

  • Config_Reader $reader required - $source Config_Reader instance

Return Values

  • $this

Source Code

public function detach(Config_Reader $reader)
{
	if (($key = array_search($reader, $this->_readers)) !== FALSE)
	{
		// Remove the writer
		unset($this->_readers[$key]);
	}

	return $this;
}

public static instance( ) (defined in Kohana_Config)

Get the singleton instance of Config.

$config = Config::instance();

Return Values

  • Config

Source Code

public static function instance()
{
	if (Config::$_instance === NULL)
	{
		// Create a new instance
		Config::$_instance = new Config;
	}

	return Config::$_instance;
}

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

Load a configuration group. Searches the readers in order until the group is found. If the group does not exist, an empty configuration array will be loaded using the first reader.

$array = $config->load($name);

Parameters

  • string $group required - Configuration group name

Tags

Return Values

  • Config_Reader

Source Code

public function load($group)
{
	foreach ($this->_readers as $reader)
	{
		if ($config = $reader->load($group))
		{
			// Found a reader for this configuration group
			return $config;
		}
	}

	// Reset the iterator
	reset($this->_readers);

	if ( ! is_object($config = current($this->_readers)))
	{
		throw new Kohana_Exception('No configuration readers attached');
	}

	// Load the reader as an empty array
	return $config->load($group, array());
}