Source for file Config.class.php
Documentation is available at Config.class.php
* Gumbo Library Framework
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* The Config Class will perform necessary operations defined by the Config
* Interface. Each operation will have a method assigned to it (read). The
* client will call the method, passing the necessary arguments. The class
* uses a Factory to search for the appropriate Config Operation (Reader).
* This will make the Config class universal to any changes made to the Config
* Package. The Factory will search inside the Config directory. It will
* setup the proper operation ('reader','writer',...) and the type of operation
* class. If it's found, the operation will be performed and the results
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
gumbo_load ("Interface_Factory");
gumbo_load ("Interface_Config");
gumbo_load ("Config_Factory");
class Gumbo_Config implements Gumbo_Interface_Config, Gumbo_Interface_Factory {
* Returns an instantiated Config Operation
* This method is primarily used internally. It will return a Config
* Operation class based on the 'type'. It works specifically on Gumbo
* defined Config Operations. The class name is automatically
* generated based on the arguments.
* The first argument 'name' will be the type of Config operation interface to
* load ('reader','writer',...).
* The second argument 'args' will be a string determining what type
* of operation class to find ('ini','php',...). This isn't restricted to
* a file type, but to a defined Config Operation Class. The type name could
* be 'foo', and it would load the 'Gumbo_Config_[Reader]_Foo' class (if calling
* for a 'Reader' operation).
* @param string $name configuration interface
* @param string $args type of configuration interface class
* @return Gumbo_Interface_Config_*
* @throws Gumbo_Exception
public function factory ($name=
null, $args=
null) {
// set the Config class name
$class_name =
"Gumbo_Config_{$name}_{$type}";
if (!class_exists ($class_name, false) &&
!gumbo_load ($class_name)) {
throw
new Gumbo_Exception_Class ("Class Does Not Exist: {$class_name}");
return new $class_name ();
$e->setFunction (__METHOD__
);
* Reads the configuration file and returns the values
* @param string $file file to load (full path)
* @param string $type type of configuration file
* @return Gumbo_Interface_Composite
* @throws Gumbo_Exception
* @see Gumbo_Interface_Composite
public function read ($file, $type=
"ini") {
$e->setFunction (__METHOD__
);
$tree =
$reader->read ($file);
$e->setFunction (__METHOD__
);
* Writes a configuration file
* @param Gumbo_Interface_Composite $tree data to write
* @param string $file file name (full path)
* @param string $type type of configuration file
* @param bool $replace replaces the current file
* @return bool if operation was successful
* @throws Gumbo_Exception
* @see Gumbo_Interface_Composite
public function write (Gumbo_Interface_Composite $tree, $file, $type=
"ini", $replace=
true) {
$e->setFunction (__METHOD__
);
$e->setFunction (__METHOD__
);
return $writer->write ($tree, $file, $replace);
$e->setFunction (__METHOD__
);