Added logic to traverse the filesystem in an attempt to locate the configuration. Errors if it gets to /. Comes into play when using command line scripts that may live in sub-directories of the ./scripts directory.

This commit is contained in:
Josh Sherman 2011-05-03 23:14:37 -04:00
parent aa3427a25c
commit 4e6098bc86

View file

@ -44,11 +44,36 @@ class Config extends Object
*
* @param string $filename optional Filename of the config
*/
public function __construct($filename = '../config.php')
public function __construct($filename = null)
{
parent::__construct();
$this->load($filename);
// Try to fine the configuration
if ($filename == null)
{
$filename = 'config.php';
$loaded = false;
$cwd = getcwd();
while ($loaded == false)
{
chdir(dirname($filename));
if (getcwd() == '/')
{
throw new Exception('Unable to load configuration.');
}
chdir($cwd);
$filename = '../' . $filename;
$loaded = $this->load($filename);
}
}
else
{
$this->load($filename);
}
}
/**