Navigation Menu

Skip to content

Commit

Permalink
Removing __cache property that can be altered outside of the class de…
Browse files Browse the repository at this point in the history
…finition.

Adding __resetCache() as a replacement for checking if cache should be reset and written.
  • Loading branch information
phpnut committed Nov 17, 2010
1 parent e6e50e8 commit 15f5a00
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions cake/libs/configure.php
Expand Up @@ -109,13 +109,6 @@ class Configure extends Object {
* @access public
*/
var $debug = null;
/**
* Determines if $__objects cache should be written.
*
* @var boolean
* @access private
*/
var $__cache = false;
/**
* Holds and key => value array of objects' types.
*
Expand Down Expand Up @@ -203,7 +196,7 @@ function listObjects($type, $path = null, $cache = true) {
}
if ($cache === true && !empty($objects)) {
$_this->__objects[$name] = $objects;
$_this->__cache = true;
$_this->__resetCache(true);
} else {
return $objects;
}
Expand Down Expand Up @@ -685,13 +678,27 @@ function __loadBootstrap($boot) {
));
}
}
/**
* Determines if $__objects cache should be reset.
*
* @param boolean $reset
* @return boolean
* @access private
*/
function __resetCache($reset = null) {
static $cache = array();
if (!$cache && $reset === true) {
$cache = true;
}
return $cache;
}
/**
* Caches the object map when the instance of the Configure class is destroyed
*
* @access public
*/
function __destruct() {
if ($this->__cache) {
if ($this->__resetCache() === true) {
Cache::write('object_map', array_filter($this->__objects), '_cake_core_');
}
}
Expand Down Expand Up @@ -719,13 +726,6 @@ class App extends Object {
* @access public
*/
var $return = false;
/**
* Determines if $__maps and $__paths cache should be written.
*
* @var boolean
* @access private
*/
var $__cache = false;
/**
* Holds key/value pairs of $type => file path.
*
Expand Down Expand Up @@ -835,7 +835,7 @@ function import($type = null, $name = null, $parent = true, $search = array(), $
return true;
} else {
$_this->__remove($name . $ext['class'], $type, $plugin);
$_this->__cache = true;
$_this->__resetCache(true);
}
}
if (!empty($search)) {
Expand Down Expand Up @@ -867,7 +867,7 @@ function import($type = null, $name = null, $parent = true, $search = array(), $
}

if ($directory !== null) {
$_this->__cache = true;
$_this->__resetCache(true);
$_this->__map($directory . $file, $name . $ext['class'], $type, $plugin);
$_this->__overload($type, $name . $ext['class']);

Expand Down Expand Up @@ -1161,6 +1161,20 @@ function __remove($name, $type, $plugin) {
unset($this->__map[$type][$name]);
}
}
/**
* Determines if $__maps and $__paths cache should be reset.
*
* @param boolean $reset
* @return boolean
* @access private
*/
function __resetCache($reset = null) {
static $cache = array();
if (!$cache && $reset === true) {
$cache = true;
}
return $cache;
}
/**
* Object destructor.
*
Expand All @@ -1170,7 +1184,7 @@ function __remove($name, $type, $plugin) {
* @access private
*/
function __destruct() {
if ($this->__cache) {
if ($this->__resetCache() === true) {
$core = Configure::corePaths('cake');
unset($this->__paths[rtrim($core[0], DS)]);
Cache::write('dir_map', array_filter($this->__paths), '_cake_core_');
Expand Down

0 comments on commit 15f5a00

Please sign in to comment.