mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Making Configure::load merge by default. Adding a test case for overwriting. Fixes #1618
This commit is contained in:
parent
dd245747e8
commit
f4d8a7eff1
2 changed files with 30 additions and 9 deletions
|
@ -272,9 +272,9 @@ class Configure {
|
||||||
* Loads stored configuration information from a resource. You can add
|
* Loads stored configuration information from a resource. You can add
|
||||||
* config file resource readers with `Configure::config()`.
|
* config file resource readers with `Configure::config()`.
|
||||||
*
|
*
|
||||||
* Loaded configuration infomration will be merged with the current
|
* Loaded configuration information will be merged with the current
|
||||||
* runtime configuration. You can load configuration files from plugins
|
* runtime configuration. You can load configuration files from plugins
|
||||||
* by preceeding the filename with the plugin name.
|
* by preceding the filename with the plugin name.
|
||||||
*
|
*
|
||||||
* `Configure::load('Users.user', 'default')`
|
* `Configure::load('Users.user', 'default')`
|
||||||
*
|
*
|
||||||
|
@ -285,12 +285,12 @@ class Configure {
|
||||||
*
|
*
|
||||||
* @link http://book.cakephp.org/view/929/load
|
* @link http://book.cakephp.org/view/929/load
|
||||||
* @param string $key name of configuration resource to load.
|
* @param string $key name of configuration resource to load.
|
||||||
* @param string $config Name of the configured reader to use to read the resource identfied by $key.
|
* @param string $config Name of the configured reader to use to read the resource identified by $key.
|
||||||
* @param boolean $merge if config files should be merged instead of simply overridden
|
* @param boolean $merge if config files should be merged instead of simply overridden
|
||||||
* @return mixed false if file not found, void if load successful.
|
* @return mixed false if file not found, void if load successful.
|
||||||
* @throws ConfigureException Will throw any exceptions the reader raises.
|
* @throws ConfigureException Will throw any exceptions the reader raises.
|
||||||
*/
|
*/
|
||||||
public static function load($key, $config = 'default', $merge = false) {
|
public static function load($key, $config = 'default', $merge = true) {
|
||||||
if (!isset(self::$_readers[$config])) {
|
if (!isset(self::$_readers[$config])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,11 +193,11 @@ class ConfigureTest extends CakeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test load
|
* test load with merging
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testLoad() {
|
function testLoadWithMerge() {
|
||||||
Configure::config('test', new PhpReader(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config' . DS));
|
Configure::config('test', new PhpReader(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config' . DS));
|
||||||
|
|
||||||
$result = Configure::load('var_test', 'test');
|
$result = Configure::load('var_test', 'test');
|
||||||
|
@ -213,6 +213,27 @@ class ConfigureTest extends CakeTestCase {
|
||||||
$this->assertEquals('buried', Configure::read('Deep.Deeper.Deepest'));
|
$this->assertEquals('buried', Configure::read('Deep.Deeper.Deepest'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test loading with overwrite
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testLoadNoMerge() {
|
||||||
|
Configure::config('test', new PhpReader(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config' . DS));
|
||||||
|
|
||||||
|
$result = Configure::load('var_test', 'test');
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
$this->assertEquals('value', Configure::read('Read'));
|
||||||
|
|
||||||
|
$result = Configure::load('var_test2', 'test', false);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
$this->assertEquals('value2', Configure::read('Read'));
|
||||||
|
$this->assertEquals('buried2', Configure::read('Deep.Second.SecondDeepest'));
|
||||||
|
$this->assertNull(Configure::read('Deep.Deeper.Deepest'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testLoad method
|
* testLoad method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue