Skip to content
Browse files

Ensure Configure::boostrap() doesn't overwrite existing configs under…

… 'App' key.

Fixes #3874
  • Loading branch information...
1 parent 6da0a37 commit b7cee8ff57e15a5b13ec4fdd6d083190b4dbdc16 @ADmad ADmad committed
Showing with 36 additions and 11 deletions.
  1. +15 −7 lib/Cake/Core/Configure.php
  2. +17 −0 lib/Cake/Test/Case/Core/ConfigureTest.php
  3. +4 −4 lib/Cake/bootstrap.php
View
22 lib/Cake/Core/Configure.php
@@ -67,13 +67,7 @@ class Configure {
*/
public static function bootstrap($boot = true) {
if ($boot) {
- self::write('App', array(
- 'base' => false,
- 'baseUrl' => false,
- 'dir' => APP_DIR,
- 'webroot' => WEBROOT_DIR,
- 'www_root' => WWW_ROOT
- ));
+ self::_appDefaults();
if (!include APP . 'Config' . DS . 'core.php') {
trigger_error(__d('cake_dev', "Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", APP . 'Config' . DS), E_USER_ERROR);
@@ -110,6 +104,20 @@ class_exists('String');
}
/**
+ * Set app's default configs
+ * @return void
+ */
+ protected static function _appDefaults() {
+ self::write('App', (array)self::read('App') + array(
+ 'base' => false,
+ 'baseUrl' => false,
+ 'dir' => APP_DIR,
+ 'webroot' => WEBROOT_DIR,
+ 'www_root' => WWW_ROOT
+ ));
+ }
+
+/**
* Used to store a dynamic variable in Configure.
*
* Usage:
View
17 lib/Cake/Test/Case/Core/ConfigureTest.php
@@ -70,6 +70,23 @@ public function tearDown() {
}
/**
+ * Test to ensure bootrapping doesn't overwrite prior configs set under 'App' key
+ * @return void
+ */
+ public function testBootstrap() {
+ $expected = array(
+ 'foo' => 'bar'
+ );
+ Configure::write('App', $expected);
+
+ Configure::bootstrap(true);
+ $result = Configure::read('App');
+
+ $this->assertEquals($expected['foo'], $result['foo']);
+ $this->assertFalse($result['base']);
+ }
+
+/**
* testRead method
*
* @return void
View
8 lib/Cake/bootstrap.php
@@ -150,10 +150,6 @@
App::uses('Object', 'Core');
App::uses('Multibyte', 'I18n');
-App::$bootstrapping = true;
-
-Configure::bootstrap(isset($boot) ? $boot : true);
-
/**
* Full URL prefix
*/
@@ -172,6 +168,10 @@
unset($httpHost, $s);
}
+App::$bootstrapping = true;
+
+Configure::bootstrap(isset($boot) ? $boot : true);
+
if (function_exists('mb_internal_encoding')) {
$encoding = Configure::read('App.encoding');
if (!empty($encoding)) {

0 comments on commit b7cee8f

Please sign in to comment.
Something went wrong with that request. Please try again.