Skip to content

Commit

Permalink
The 'default' config for Configure class is now auto created on first…
Browse files Browse the repository at this point in the history
… use if not already created.
  • Loading branch information
ADmad committed Sep 17, 2011
1 parent 0e5797d commit 08026e5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Cake/Core/Configure.php
Expand Up @@ -287,6 +287,9 @@ public static function drop($name) {
*
* `Configure::load('setup', 'default');`
*
* If using `default` config and no reader has been configured for it yet,
* one will be automatically created using PhpReader
*
* @link http://book.cakephp.org/view/929/load
* @param string $key name of configuration resource to load.
* @param string $config Name of the configured reader to use to read the resource identified by $key.
Expand All @@ -296,7 +299,12 @@ public static function drop($name) {
*/
public static function load($key, $config = 'default', $merge = true) {
if (!isset(self::$_readers[$config])) {
return false;
if ($config === 'default') {
App::uses('PhpReader', 'Configure');
self::$_readers[$config] = new PhpReader();
} else {
return false;
}
}
$values = self::$_readers[$config]->read($key);

Expand Down
14 changes: 14 additions & 0 deletions lib/Cake/Test/Case/Core/ConfigureTest.php
Expand Up @@ -191,6 +191,20 @@ public function testLoadExceptionOnNonExistantFile() {
$result = Configure::load('non_existing_configuration_file', 'test');
}

/**
* test load method for default config creation
*
* @return void
*/
public function testLoadDefaultConfig() {
try {
Configure::load('non_existing_configuration_file');
} catch (Exception $e) {
$result = Configure::configured('default');
$this->assertTrue($result);
}
}

/**
* test load with merging
*
Expand Down

0 comments on commit 08026e5

Please sign in to comment.