Skip to content

Commit

Permalink
use a boolean flag for loading default config
Browse files Browse the repository at this point in the history
this prevents problems where the configarray is emptied deliberately and
then unintnetionally re-loaded with the default config
  • Loading branch information
AD7six committed Mar 25, 2014
1 parent de7ec70 commit 7d224d7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Core/InstanceConfigTrait.php
Expand Up @@ -30,6 +30,13 @@ trait InstanceConfigTrait {
*/
protected $_config = [];

/**
* Whether the config property has already been configured with defaults
*
* @var bool
*/
protected $_configInitialized = false;

/**
* ### Usage
*
Expand Down Expand Up @@ -63,8 +70,9 @@ trait InstanceConfigTrait {
* @throws \Cake\Error\Exception When trying to set a key that is invalid
*/
public function config($key = null, $value = null) {
if ($this->_config === [] && $this->_defaultConfig) {
if (!$this->_configInitialized) {
$this->_config = $this->_defaultConfig;
$this->_configInitialized = true;
}

if (is_array($key) || func_num_args() === 2) {
Expand Down

0 comments on commit 7d224d7

Please sign in to comment.