Implements: IteratorAggregate | Traversable | ArrayAccess | Serializable | Countable
File-based configuration reader. Multiple configuration directories can be used by attaching multiple instances of this class to Config.
Class declared in SYSPATH/classes/config/file.php on line 3.
integer 1
integer 2
string
$_configuration_groupConfiguration group name
bool
$_configuration_modifiedHas the config group changed?
Loads an empty array as the initial configuration and enables array keys to be used as properties.
void
public function __construct($directory = 'config')
{
// Set the configuration directory name
$this->_directory = trim($directory, '/');
// Load the empty array
parent::__construct();
}
Load and merge all of the configuration files in this group.
$config->load($name);
string
$group
required - Configuration group namearray
$config
= NULL - Configuration array$this
- Clone of the current objectpublic function load($group, array $config = NULL)
{
if ($files = Kohana::find_file($this->_directory, $group, NULL, TRUE))
{
// Initialize the config array
$config = array();
foreach ($files as $file)
{
// Merge each file to the configuration array
$config = Arr::merge($config, Kohana::load($file));
}
}
return parent::load($group, $config);
}
Return the current group in serialized form.
echo $config;
string
public function __toString()
{
return serialize($this->getArrayCopy());
}
Return the raw array that is being used for this object.
$array = $config->as_array();
array
public function as_array()
{
return $this->getArrayCopy();
}
Get a variable from the configuration or return the default value.
$value = $config->get($key);
string
$key
required - Array keymixed
$default
= NULL - Default valuemixed
public function get($key, $default = NULL)
{
return $this->offsetExists($key) ? $this->offsetGet($key) : $default;
}
Sets a value in the configuration array.
$config->set($key, $new_value);
string
$key
required - Array keymixed
$value
required - Array value$this
public function set($key, $value)
{
$this->offsetSet($key, $value);
return $this;
}