Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

namespace DDDBL;
* simple implementation of generic singleton
* for all classes, which allows additional instances
* if needed
class Singleton {
* @param $strClass - the class we want an instance from
* @throws UnexpectedParameterTypeException - if given parameter is not a string
* @throws \Exception - if given class do not exists
* @return (object) - an instance of the given classname
* get a reference to the instance of the given class.
* if instance do not exists, create one. after creation
* always return reference to this reference
static function getInstance($strClass) {
throw new UnexpectedParameterTypeException('string', $strClass);
throw new \Exception ("class do not exists: $strClass");
static $arrObjectList = array();
$arrObjectList[$strClass] = new $strClass();
return $arrObjectList[$strClass];