Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I feel like this can be done better or something is missing or wrongCode: Select all
class SpotSec_Singleton
{
/**
* Stores instances
*
* @var array
*/
static private $_instances = array();
/**
* Singleton Pattern
*/
private function __construct()
{}
/**
* Returns an instance of a class. $instanceName can be used to create
* multitons.
*
* @param string $class
* @param string $instanceName
* @return class
*/
static public function &getInstance($class, $instanceName = null)
{
$instance =& self::$_instances[$instanceName][$class];
if (!isset($instance) && !$instance instanceof $class) {
$instance = new $class;
}
return $instance;
}
/**
* Removes an instance of a class
*
* @param string $class
* @param string $instanceName
*/
static public function removeInstance($class, $instanceName = null)
{
$instance =& self::$_instances[$instanceName][$class];
if (isset($instance) && $instance instanceof $class) {
unset(self::$_instances[$instanceName][$class]);
}
}
}feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]