diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2012-01-30 20:24:49 -0800 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2012-01-30 20:24:49 -0800 |
commit | bbede7f65093c4f85a99dc94282809436effc799 (patch) | |
tree | b6819bd0f2defca621cea1927f1f9e2f4767ef28 /includes | |
parent | c367b7d954e04cd10008c0f6111cb36c67b0ba0c (diff) | |
download | brdo-bbede7f65093c4f85a99dc94282809436effc799.tar.gz brdo-bbede7f65093c4f85a99dc94282809436effc799.tar.bz2 |
Issue #1371484 by catch, langworthy, makara, ArtistConk: Fixed Private properties in abstract class DrupalCacheArray.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/bootstrap.inc | 18 | ||||
-rw-r--r-- | includes/common.inc | 2 | ||||
-rw-r--r-- | includes/theme.inc | 42 |
3 files changed, 35 insertions, 27 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 425a74acb..4ef4f2b83 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -289,12 +289,12 @@ abstract class DrupalCacheArray implements ArrayAccess { /** * A cid to pass to cache_set() and cache_get(). */ - private $cid; + protected $cid; /** * A bin to pass to cache_set() and cache_get(). */ - private $bin; + protected $bin; /** * An array of keys to add to the cache at the end of the request. @@ -393,24 +393,20 @@ abstract class DrupalCacheArray implements ArrayAccess { /** * Writes a value to the persistent cache immediately. * - * @param $cid - * The cache ID. - * @param $bin - * The cache bin. * @param $data * The data to write to the persistent cache. * @param $lock * Whether to acquire a lock before writing to cache. */ - protected function set($cid, $data, $bin, $lock = TRUE) { + protected function set($data, $lock = TRUE) { // Lock cache writes to help avoid stampedes. // To implement locking for cache misses, override __construct(). - $lock_name = $cid . ':' . $bin; + $lock_name = $this->cid . ':' . $this->bin; if (!$lock || lock_acquire($lock_name)) { - if ($cached = cache_get($cid, $bin)) { + if ($cached = cache_get($this->cid, $this->bin)) { $data = $cached->data + $data; } - cache_set($cid, $data, $bin); + cache_set($this->cid, $data, $this->bin); if ($lock) { lock_release($lock_name); } @@ -428,7 +424,7 @@ abstract class DrupalCacheArray implements ArrayAccess { } } if (!empty($data)) { - $this->set($this->cid, $data, $this->bin); + $this->set($data); } } } diff --git a/includes/common.inc b/includes/common.inc index b07bf9669..5e90f78f1 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2370,7 +2370,7 @@ function l($text, $path, array $options = array()) { // rendering. if (variable_get('theme_link', TRUE)) { drupal_theme_initialize(); - $registry = theme_get_registry(); + $registry = theme_get_registry(FALSE); // We don't want to duplicate functionality that's in theme(), so any // hint of a module or theme doing anything at all special with the 'link' // theme hook should simply result in theme() being called. This includes diff --git a/includes/theme.inc b/includes/theme.inc index 9a921decc..da4200e56 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -372,23 +372,31 @@ class ThemeRegistry Extends DrupalCacheArray { $data = $cached->data; } else { - $complete_registry = theme_get_registry(); + // If there is no runtime cache stored, fetch the full theme registry, + // but then initialize each value to NULL. This allows offsetExists() + // to function correctly on non-registered theme hooks without triggering + // a call to resolveCacheMiss(). + $data = $this->initializeRegistry(); if ($this->persistable) { - // If there is no runtime cache stored, fetch the full theme registry, - // but then initialize each value to NULL. This allows - // offsetExists() to function correctly on non-registered theme hooks - // without triggering a call to resolveCacheMiss(). - $data = array_fill_keys(array_keys($complete_registry), NULL); - $this->set($this->cid, $data, $this->bin); - $this->completeRegistry = $complete_registry; - } - else { - $data = $complete_registry; + $this->set($data); } } $this->storage = $data; } + /** + * Initializes the full theme registry. + * + * @return + * An array with the keys of the full theme registry, but the values + * initialized to NULL. + */ + function initializeRegistry() { + $this->completeRegistry = theme_get_registry(); + + return array_fill_keys(array_keys($this->completeRegistry), NULL); + } + public function offsetExists($offset) { // Since the theme registry allows for theme hooks to be requested that // are not registered, just check the existence of the key in the registry. @@ -420,15 +428,19 @@ class ThemeRegistry Extends DrupalCacheArray { return $this->storage[$offset]; } - public function set($cid, $data, $bin, $lock = TRUE) { - $lock_name = $cid . ':' . $bin; + public function set($data, $lock = TRUE) { + $lock_name = $this->cid . ':' . $this->bin; if (!$lock || lock_acquire($lock_name)) { - if ($cached = cache_get($cid, $this->bin)) { + if ($cached = cache_get($this->cid, $this->bin)) { // Use array merge instead of union so that filled in values in $data // overwrite empty values in the current cache. $data = array_merge($cached->data, $data); } - cache_set($cid, $data, $bin); + else { + $registry = $this->initializeRegistry(); + $data = array_merge($registry, $data); + } + cache_set($this->cid, $data, $this->bin); if ($lock) { lock_release($lock_name); } |