diff --git a/includes/theme.inc b/includes/theme.inc index 67cbe85..fe99797 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -279,21 +279,7 @@ function _theme_registry_callback($callback = NULL, array $arguments = array()) * The name of the theme engine. */ function _theme_load_registry($theme, $base_theme = NULL, $theme_engine = NULL) { - // Check the theme registry cache; if it exists, use it. - $cache = cache_get("theme_registry:$theme->name", 'cache'); - if (isset($cache->data)) { - $registry = $cache->data; - } - else { - // If not, build one and cache it. - $registry = _theme_build_registry($theme, $base_theme, $theme_engine); - // Only persist this registry if all modules are loaded. This assures a - // complete set of theme hooks. - if (module_load_all(NULL)) { - _theme_save_registry($theme, $registry); - } - } - return $registry; + return new ThemeRegistry($theme, $base_theme, $theme_engine); } /** @@ -562,6 +548,53 @@ function _theme_build_registry($theme, $base_theme, $theme_engine) { return $cache; } +class ThemeRegistry Implements ArrayAccess { + protected $registry = array(); + + function __construct($theme, $base_theme = NULL, $theme_engine = NULL) { + $this->theme = $theme; + $this->base_theme = $base_theme; + $this->theme_engine = $theme_engine; + + if ($cached = cache_get("theme_registry:$theme->name", 'cache')) { + $this->registry = $cached->data; + } + else { + $this->registry = _theme_build_registry($theme, $base_theme, $theme_engine); + // Only persist this registry if all modules are loaded. This assures a + // complete set of theme hooks. + if (module_load_all(NULL)) { + _theme_save_registry($theme, $registry); + } + } + } + + public function offsetExists($offset) { + return isset($this->registry[$offset]); + } + + public function offsetGet($offset) { + if (isset($this->registry[$offset])) { + return $this->registry[$offset]; + } + else { + return NULL; + } + } + + public function offsetSet($offset, $value) { + if (!isset($offset)) { + $this->registry[$offset] = $value; + } + else { + $this->registry[] = $value; + } + } + public function offsetUnset($offset) { + unset($this->registry[$offset]); + } +} + /** * Return a list of all currently available themes. *