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:
parent
aa3427a25c
commit
4e6098bc86
1 changed files with 27 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue