Index: class.t3lib_div.php =================================================================== --- class.t3lib_div.php (revision 5928) +++ class.t3lib_div.php (working copy) @@ -284,6 +284,8 @@ const HTTP_STATUS_504 = 'HTTP/1.1 504 Gateway Timeout'; const HTTP_STATUS_505 = 'HTTP/1.1 505 Version Not Supported'; + // holds references of singletons + protected static $instances = array(); /************************* @@ -4903,6 +4905,31 @@ } /** + * Adds or replaces the given object in the internal instances collection + * After that, t3lib_div::instance() will return the specified $isntance for + * $className + * + * @param string Class name to instantiate + * @param string Class name to instantiate + * @return void + */ + public static function registerInstance($className, $instance) { + self::$instances[$className] = $instance; + } + + /** + * Removes the specified class from the internal instances collection + * + * @param string Class name to instantiate + * @return void + */ + public static function unregisterInstance($className) { + if (isset(self::$instances[$className])) { + unset(self::$instances[$className]); + } + } + + /** * Creates an instance of a class taking into account the class-extensions * API of TYPO3. USE THIS method instead of the PHP "new" keyword. * Eg. "$obj = new myclass;" should be "$obj = t3lib_div::makeInstance("myclass")" instead! @@ -4913,15 +4940,12 @@ * @return object A reference to the object */ public static function &makeInstance($className) { - // holds references of singletons - static $instances = array(); - // Get final classname $className = self::getClassName($className); - if (isset($instances[$className])) { + if (isset(self::$instances[$className])) { // it's a singleton, get the existing instance - $instance = $instances[$className]; + $instance = self::$instances[$className]; } else { if (func_num_args() > 1) { // getting the constructor arguments by removing this @@ -4937,7 +4961,7 @@ if ($instance instanceof t3lib_Singleton) { // it's a singleton, save the instance for later reuse - $instances[$className] = $instance; + self::$instances[$className] = $instance; } }