* @package generis */ abstract class common_cache_SingletonCache { // --- ASSOCIATIONS --- // --- ATTRIBUTES --- /** * Short description of attribute instances * * @access private * @var array */ private static $instances = []; // --- OPERATIONS --- /** * Short description of method singleton * * @access public * @author Joel Bout, * @return common_cache_Cache */ public static function singleton() { $returnValue = null; $cacheName = get_called_class(); if (!isset(self::$instances[$cacheName])) { self::$instances[$cacheName] = new $cacheName(); } $returnValue = self::$instances[$cacheName]; return $returnValue; } /** * Short description of method getCached * * @access public * @author Joel Bout, * @param function */ public static function getCached($function) { $returnValue = null; $args = func_get_args(); array_shift($args); if (!is_string($function)) { $r = new ReflectionFunction($function); $serial = md5( $r->getFileName() . $r->getStartLine() . serialize($args) ); } else { $serial = md5($function . serialize($args)); } if (static::singleton()->has($serial)) { $returnValue = static::singleton()->has($serial); } else { $returnValue = call_user_func_array($fn, $args); static::singleton()->put($serial, $returnValue); } return $returnValue; } /** * Short description of method __construct * * @access private * @author Joel Bout, * @return mixed */ private function __construct() { } } /* end of abstract class common_cache_SingletonCache */