[TYPO3-core] RFC #9505: Make the caches in TYPO3 use the new caching framework

Robert Lemke robert at typo3.org
Wed Oct 8 14:03:12 CEST 2008


Hi Martin,

On 08.10.2008, at 13:41, Martin Kutschker wrote:

> A simple solution is to have all singletons have a certain "magic"
> property eg t3libSingleton. It doesn't matter if that is inherited  
> from
> an abstract singleton class or if it's an implementation of an  
> interface
> *. The only purpose is that it's presence can be detected with
> property_exists() which works on classes (and objects). Mind that it's
> of no important which value the property has, setting it to 0, NULL or
> FALSE will not change the behaviour!
>
> This way we can avoid the reflection. We don't use it in 4.x and I  
> don't
> think we should bring it into the codebase.

Hmm, magic .... how about this one (demo code, not tested):

interface t3lib_singleton {
}

class tx_myextension_myclass implements t3lib_singleton {
}

class t3lib_div {

	static $instances = array();

	public static function makeInstance($className, ...) {
		if (isset(self::$instances[$className])) return self:: 
$instances[$className];
		$instance = new $className();
		if ($instance instanceof t3lib_singleton) self:: 
$instances[$className] = $instance;
		return $instance;
	}
}

How about that?

robert

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://lists.netfielders.de/pipermail/typo3-team-core/attachments/20081008/82704055/attachment.pgp 


More information about the TYPO3-team-core mailing list