Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.243 diff -u -p -r1.243 bootstrap.inc --- includes/bootstrap.inc 31 Oct 2008 02:18:22 -0000 1.243 +++ includes/bootstrap.inc 1 Nov 2008 22:03:40 -0000 @@ -496,7 +496,7 @@ function conf_init() { * The filename of the requested item. */ function drupal_get_filename($type, $name, $filename = NULL) { - static $files = array(); + $files =& statics()->value('files'); if (!isset($files[$type])) { $files[$type] = array(); @@ -1290,6 +1290,87 @@ function ip_address($reset = FALSE) { } /** + * Singleton class for the central static caching facility. + */ +class Statics { + + /** + * Singleton instance variable + * + * @var Statics + */ + protected static $instance; + + /** + * Central static cache array. + * + * @var array + */ + protected $cache = array(); + + /** + * Accessor for the singleton object. + */ + public static function instance() { + if (empty(self::$instance)) { + self::$instance = new self(); + } + } + + /** + * Retrieves the statically cached specified value. + * + * This method must be called by reference. + * + * @param $name + * Unique key for the value being cached. + * @param $default + * The default value for the specified key if it hasn't been created yet. + * @return + * A reference to the requested static variable. + */ + public function &value($name, $default = NULL) { + // Store the default, if not yet set to a non-NULL value. + if (!isset($this->cache[$name]['default'])) { + $this->cache[$name]['default'] = $default; + $this->cache[$name]['data'] = $default; + } + return $this->cache[$name]['data']; + } + + /** + * Reset a statically cached value. + * + * If the value has no default specified yet, it will be set to NULL. + * + * @param $name + * The name of the value to be reset. + */ + public function reset($name = NULL) { + if (isset($name)) { + if (!isset($this->cache[$name]['default'])) { + $this->cache[$name]['default'] = NULL; + } + $this->cache[$name]['data'] = $this->cache[$name]['default']; + } + else { + $this->cache = array(); + } + } + +} + +/** + * Singleton factory wrapper for the Statics class. + * + * @return + * The Statics singleton. + */ +function statics() { + return Statics::instance(); +} + +/** * @ingroup schemaapi * @{ */