From 08026e58289d8f249517a82ca1a66b7ed92c390a Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 18 Sep 2011 00:00:39 +0530 Subject: [PATCH] The 'default' config for Configure class is now auto created on first use if not already created. --- lib/Cake/Core/Configure.php | 10 +++++++++- lib/Cake/Test/Case/Core/ConfigureTest.php | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Core/Configure.php b/lib/Cake/Core/Configure.php index c91212d3d..ad1392e88 100644 --- a/lib/Cake/Core/Configure.php +++ b/lib/Cake/Core/Configure.php @@ -287,6 +287,9 @@ class Configure { * * `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. @@ -296,7 +299,12 @@ class Configure { */ 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); diff --git a/lib/Cake/Test/Case/Core/ConfigureTest.php b/lib/Cake/Test/Case/Core/ConfigureTest.php index fdb1475d8..8f79c5381 100644 --- a/lib/Cake/Test/Case/Core/ConfigureTest.php +++ b/lib/Cake/Test/Case/Core/ConfigureTest.php @@ -191,6 +191,20 @@ class ConfigureTest extends CakeTestCase { $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 *