From 8d70c0af8f395cfa6354e4e586b156f65954fca3 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sat, 17 Aug 2013 07:31:29 +0200 Subject: Fix $replace parameter handling in get_config() Code was reached only on first function call, then short-circuited because of the reference cache. --- system/core/CodeIgniter.php | 2 +- system/core/Common.php | 58 ++++++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index a026920a4..c962fda20 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -88,7 +88,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * The subclass prefix allows CI to know if a core class is * being extended via a library in the local application * "libraries" folder. Since CI allows config items to be - * overriden via data set in the main index. php file, + * overriden via data set in the main index.php file, * before proceeding we need to know if a subclass_prefix * override exists. If so, we will set this value now, * before any classes are loaded diff --git a/system/core/Common.php b/system/core/Common.php index 21e1df9c6..a90a3ab70 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -230,39 +230,43 @@ if ( ! function_exists('get_config')) if (isset($_config)) { - return $_config[0]; + $config =& $_config[0]; } - - $file_path = APPPATH.'config/config.php'; - $found = FALSE; - if (file_exists($file_path)) + else { - $found = TRUE; - require($file_path); - } + $file_path = APPPATH.'config/config.php'; + $found = FALSE; + if (file_exists($file_path)) + { + $found = TRUE; + require($file_path); + } - // Is the config file in the environment folder? - if (file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) - { - require($file_path); - } - elseif ( ! $found) - { - set_status_header(503); - echo 'The configuration file does not exist.'; - exit(EXIT_CONFIG); - } + // Is the config file in the environment folder? + if (file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) + { + require($file_path); + } + elseif ( ! $found) + { + set_status_header(503); + echo 'The configuration file does not exist.'; + exit(EXIT_CONFIG); + } - // Does the $config array exist in the file? - if ( ! isset($config) OR ! is_array($config)) - { - set_status_header(503); - echo 'Your config file does not appear to be formatted correctly.'; - exit(EXIT_CONFIG); + // Does the $config array exist in the file? + if ( ! isset($config) OR ! is_array($config)) + { + set_status_header(503); + echo 'Your config file does not appear to be formatted correctly.'; + exit(EXIT_CONFIG); + } + + $_config[0] =& $config; } // Are any values being dynamically replaced? - if (count($replace) > 0) + if (!empty($replace)) { foreach ($replace as $key => $val) { @@ -273,7 +277,7 @@ if ( ! function_exists('get_config')) } } - return $_config[0] =& $config; + return $config; } } -- cgit v1.2.3-24-g4f1b From 2f7810a36b488a1b3d3dfd3ba8eb6bfbbe91f9ff Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 19 Aug 2013 04:46:26 +0200 Subject: Ensure get_config() optional argument is an array, remove useless test --- system/core/Common.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index a90a3ab70..50bcd9278 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -224,7 +224,7 @@ if ( ! function_exists('get_config')) * @param array * @return array */ - function &get_config($replace = array()) + function &get_config(array $replace = array()) { static $_config; @@ -266,14 +266,11 @@ if ( ! function_exists('get_config')) } // Are any values being dynamically replaced? - if (!empty($replace)) + foreach ($replace as $key => $val) { - foreach ($replace as $key => $val) + if (isset($config[$key])) { - if (isset($config[$key])) - { - $config[$key] = $val; - } + $config[$key] = $val; } } -- cgit v1.2.3-24-g4f1b From 67e5ca678a43a00aecd46cb6d02cfbf9c36d666b Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 19 Aug 2013 04:52:00 +0200 Subject: Allow items to be set even if they were not present yet --- system/core/Common.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index 50bcd9278..6b3d73100 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -265,13 +265,10 @@ if ( ! function_exists('get_config')) $_config[0] =& $config; } - // Are any values being dynamically replaced? + // Are any values being dynamically added or replaced? foreach ($replace as $key => $val) { - if (isset($config[$key])) - { - $config[$key] = $val; - } + $config[$key] = $val; } return $config; -- cgit v1.2.3-24-g4f1b From 05d043b38896570004fadbed8495fc99c6ef3da6 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 19 Aug 2013 04:55:34 +0200 Subject: Adjustments in static reference handling --- system/core/Common.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index 6b3d73100..cf9cd846d 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -228,11 +228,7 @@ if ( ! function_exists('get_config')) { static $_config; - if (isset($_config)) - { - $config =& $_config[0]; - } - else + if (empty($_config)) { $file_path = APPPATH.'config/config.php'; $found = FALSE; @@ -262,16 +258,17 @@ if ( ! function_exists('get_config')) exit(EXIT_CONFIG); } + // references cannot be directly assigned to static variables, so we use an array $_config[0] =& $config; } // Are any values being dynamically added or replaced? foreach ($replace as $key => $val) { - $config[$key] = $val; + $_config[0][$key] = $val; } - return $config; + return $_config[0]; } } @@ -439,7 +436,7 @@ if ( ! function_exists('log_message')) { static $_log; - if ($_log === NULL) + if (empty($_log)) { // references cannot be directly assigned to static variables, so we use an array $_log[0] =& load_class('Log', 'core'); -- cgit v1.2.3-24-g4f1b