Source for file Setting.class.php
Documentation is available at Setting.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
* @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
* @desc Load Setting Class
gumbo_load ("Interface_Load_Setting");
* The settings parameter will construct a new object from the array, overriding
* the default settings. If the value is not set, the default will be used. The
* array should contain key=>value pairs, where the key references a property of
* the object. The key should exclude the underscore of the property name. For
* example: <code>array ("ext"=>"html")</code> will set the $_ext value.
* @param array $settings list of settings in key=>val pairs
* @throws Gumbo_Exception
parent::add ("class", false);
parent::add ("ext", "php");
parent::add ("stretch", false);
parent::add ("separator", "_");
parent::add ("path", "include");
parent::add ("once", false);
parent::add ("include", false);
parent::add ("remove", null);
foreach ($settings as $key=>
$val) {
case "class" :
$this->setClass ($val); break;
case "dirs" :
$this->setDirs ($val); break;
case "once" :
$this->setOnce ($val); break;
case "path" :
$this->setPath ($val); break;
case "remove" :
$this->setRemove ($val); break;
$e->setFunction (__METHOD__
);
* Adds a key=>value pair to the setting
* @throws Gumbo_Exception
public function add ($key, $val=
null) {
case "class" :
$this->setClass ($val); break;
case "dirs" :
$this->setDirs ($val); break;
case "once" :
$this->setOnce ($val); break;
case "path" :
$this->setPath ($val); break;
case "remove" :
$this->setRemove ($val); break;
$e->setFunction (__METHOD__
);
* @throws Gumbo_Exception
public function remove ($key) {
case "class" :
parent::add ("class", false); break;
case "dirs" :
parent::add ("dirs", null); break;
case "extension" :
parent::add ("extension", "php"); break;
case "ext" :
parent::add ("extension", "php"); break;
case "once" :
parent::add ("once", false); break;
case "include" :
parent::add ("include", false); break;
case "stretch" :
parent::add ("stretch", false); break;
case "separator" :
parent::add ("separator", "_"); break;
case "path" :
parent::add ("path", "include"); break;
case "remove" :
parent::add ("remove", null); break;
$e->setFunction (__METHOD__
);
* Adds a directory path to the list (additional arguments may be accepted)
* @throws Gumbo_Exception
public function addDir ($dir) {
// check if location was previously set
foreach ($this->getDirs () as $val) {
parent::add ("dirs", $tmp);
$e->setFunction (__METHOD__
);
* Sets the setting to load a class file
* @throws Gumbo_Exception
parent::add ("class", $val);
$e->setFunction (__METHOD__
);
* Adds a list of directories to the list
* There are three ways to set the Directory paths. The first method passes
* a string, with either a single directory or list of directories separated
* by the PATH_SEPARATOR constant. The second passes an array, with each
* element value a different directory. The third involves either of the first
* two methods, but multiple arguments.
* 1. $this->setDirs ("path1:path2:path3/path4");
* 2. $this->setDirs (array ("path1", "path2", "path3/path4"));
* 3. $this->setDirs ("path1", array ("path2"), "path3/path4:path5");
* @param array|string$dirs ...[]
* @throws Gumbo_Exception
// check for multiple arguments
foreach ($dirs as $dir) {
// check the path separator
if (strstr ($dirs, PATH_SEPARATOR)) {
$dirs =
explode (PATH_SEPARATOR, $dirs);
foreach ($dirs as $dir) {
$e->setFunction (__METHOD__
);
* Sets the file extension (leading "." not necessary)
* @throws Gumbo_Exception
parent::add ("ext", $ext);
$e->setFunction (__METHOD__
);
* Sets the load only once setting
* @throws Gumbo_Exception
parent::add ("once", $once);
$e->setFunction (__METHOD__
);
* Sets to use include instead of require
* @throws Gumbo_Exception
parent::add ("include", $include);
$e->setFunction (__METHOD__
);
* Sets to stretch the file name as additional directory paths
* @throws Gumbo_Exception
parent::add ("stretch", $stretch);
$e->setFunction (__METHOD__
);
* Sets the stretch separator character
* @throws Gumbo_Exception
parent::add ("separator", $sep);
$e->setFunction (__METHOD__
);
* Sets the path to start searching from.
* - include: search the include path (default)
* - home: start from Gumbo home directory
* - absolute: ignores starting point and uses dirs as absolute paths
* @throws Gumbo_Exception
parent::add ("path", $path);
$e->setFunction (__METHOD__
);
* Sets a string pattern to remove from the file name before search
* @throws Gumbo_Exception
parent::add ("remove", $remove);
$e->setFunction (__METHOD__
);
* Returns if the setting is for a class load
return $this->get ("class");
* Returns the list of directory paths
return $this->get ("dirs");
* Returns the file extension
return $this->get ("ext");
* Returns if the file should be loaded once
return $this->get ("once");
* Returns if the include function should be used instead of require
return $this->get ("include");
* Returns if the file name should stretch
return $this->get ("stretch");
* Returns the stretch separator character
return $this->get ("separator");
* Returns the path to start searching from
return $this->get ("path");
* Returns the remove string pattern
return $this->get ("remove");