summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/core/Config.php69
-rw-r--r--tests/codeigniter/core/Config_test.php13
2 files changed, 37 insertions, 45 deletions
diff --git a/system/core/Config.php b/system/core/Config.php
index d8a606c14..ca865cebf 100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -120,74 +120,61 @@ class CI_Config {
foreach ($this->_config_paths as $path)
{
- $found = FALSE;
- foreach (array(ENVIRONMENT.'/'.$file, $file) as $location)
+ foreach (array($file, ENVIRONMENT.'/'.$file) as $location)
{
$file_path = $path.'config/'.$location.'.php';
if (in_array($file_path, $this->is_loaded, TRUE))
{
- $loaded = TRUE;
- continue 2;
+ return TRUE;
}
- if (file_exists($file_path))
+ if ( ! file_exists($file_path))
{
- $found = TRUE;
- break;
+ continue;
}
- }
-
- if ($found === FALSE)
- {
- continue;
- }
- include($file_path);
+ include($file_path);
- if ( ! isset($config) OR ! is_array($config))
- {
- if ($fail_gracefully === TRUE)
+ if ( ! isset($config) OR ! is_array($config))
{
- return FALSE;
+ if ($fail_gracefully === TRUE)
+ {
+ return FALSE;
+ }
+
+ show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.');
}
- show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.');
- }
- if ($use_sections === TRUE)
- {
- if (isset($this->config[$file]))
+ if ($use_sections === TRUE)
{
- $this->config[$file] = array_merge($this->config[$file], $config);
+ $this->config[$file] = isset($this->config[$file])
+ ? array_merge($this->config[$file], $config)
+ : $config;
}
else
{
- $this->config[$file] = $config;
+ $this->config = array_merge($this->config, $config);
}
+
+ $this->is_loaded[] = $file_path;
+ $config = NULL;
+ $loaded = TRUE;
+ log_message('debug', 'Config file loaded: '.$file_path);
}
- else
+
+ if ($loaded === TRUE)
{
- $this->config = array_merge($this->config, $config);
+ return TRUE;
}
-
- $this->is_loaded[] = $file_path;
- unset($config);
-
- $loaded = TRUE;
- log_message('debug', 'Config file loaded: '.$file_path);
- break;
}
- if ($loaded === FALSE)
+ if ($fail_gracefully === TRUE)
{
- if ($fail_gracefully === TRUE)
- {
- return FALSE;
- }
- show_error('The configuration file '.$file.'.php does not exist.');
+ return FALSE;
}
- return TRUE;
+ show_error('The configuration file '.$file.'.php does not exist.');
}
// --------------------------------------------------------------------
diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php
index 8e312e361..f125fc6e9 100644
--- a/tests/codeigniter/core/Config_test.php
+++ b/tests/codeigniter/core/Config_test.php
@@ -205,13 +205,18 @@ class Config_test extends CI_TestCase {
'number' => 42,
'letter' => 'Z'
);
+
$pkg_dir = 'package';
- $this->ci_vfs_create($file.'.php', '<?php $config = '.var_export($cfg2, TRUE).';', $this->ci_app_root,
- array($pkg_dir, 'config'));
- $this->config->_config_paths[] = $this->ci_vfs_path($pkg_dir.'/', APPPATH);
+ $this->ci_vfs_create(
+ $file.'.php',
+ '<?php $config = '.var_export($cfg2, TRUE).';',
+ $this->ci_app_root,
+ array($pkg_dir, 'config')
+ );
+ array_unshift($this->config->_config_paths, $this->ci_vfs_path($pkg_dir.'/', APPPATH));
$this->assertTrue($this->config->load($file, TRUE));
$this->assertEquals(array_merge($cfg, $cfg2), $this->config->item($file));
- array_pop($this->config->_config_paths);
+ array_shift($this->config->_config_paths);
// Test graceful fail of invalid file
$file = 'badfile';