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/kohana/config.php on line 12.
protected static Kohana_Config
$_instancelink to this
Singleton static instance
object Config()
protected array
$_readerslink to this
Configuration readers
public attach( Config_Reader $reader [, boolean $first = bool TRUE ] )
(defined in Kohana_Config)
link to this
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 );
$config ->attach( $reader , FALSE);
|
Parameters
-
Config_Reader
$reader
required - Config_Reader instance
-
boolean
$first
= bool TRUE - Add the reader as the first used object
Return Values
Source Code
public function attach(Config_Reader $reader , $first = TRUE)
{
if ( $first === TRUE)
{
array_unshift ( $this ->_readers, $reader );
}
else
{
$this ->_readers[] = $reader ;
}
return $this ;
}
|
Copy one configuration group to all of the other readers.
Parameters
-
string
$group
required - Configuration group name
Return Values
Source Code
public function copy ( $group )
{
$config = $this ->load( $group );
foreach ( $this ->_readers as $reader )
{
if ( $config instanceof $reader )
{
continue ;
}
$object = $reader ->load( $group , array ());
foreach ( $config as $key => $value )
{
$object ->offsetSet( $key , $value );
}
}
return $this ;
}
|
public detach( Config_Reader $reader )
(defined in Kohana_Config)
link to this
Detach a configuration reader.
$config ->detach( $reader );
|
Parameters
-
Config_Reader
$reader
required - $source Config_Reader instance
Return Values
Source Code
public function detach(Config_Reader $reader )
{
if (( $key = array_search ( $reader , $this ->_readers)) !== FALSE)
{
unset( $this ->_readers[ $key ]);
}
return $this ;
}
|
Get the singleton instance of Config.
$config = Config::instance();
|
Return Values
Source Code
public static function instance()
{
if (Config:: $_instance === NULL)
{
Config:: $_instance = new Config;
}
return Config:: $_instance ;
}
|
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
Source Code
public function load( $group )
{
foreach ( $this ->_readers as $reader )
{
if ( $config = $reader ->load( $group ))
{
return $config ;
}
}
reset( $this ->_readers);
if ( ! is_object ( $config = current( $this ->_readers)))
{
throw new Kohana_Exception( 'No configuration readers attached' );
}
return $config ->load( $group , array ());
}
|