]> git.mxchange.org Git - friendica.git/blob - library/dddbl2/inc/Singleton.class.php
The worker settings are now available in the admin settings
[friendica.git] / library / dddbl2 / inc / Singleton.class.php
1 <?php
2
3 namespace DDDBL;
4
5 /**
6   * simple implementation of generic singleton
7   * for all classes, which allows additional instances
8   * if needed
9   *
10   **/
11   
12 class Singleton {
13
14   /**
15     * @param $strClass - the class we want an instance from
16     *
17     * @throws UnexpectedParameterTypeException - if given parameter is not a string
18     * @throws \Exception                       - if given class do not exists
19     *
20     * @return (object) - an instance of the given classname
21     *
22     * get a reference to the instance of the given class.
23     * if instance do not exists, create one. after creation
24     * always return reference to this reference
25     *
26     **/
27   static function getInstance($strClass) {
28   
29     if(!is_string($strClass))
30       throw new UnexpectedParameterTypeException('string', $strClass);
31     
32     if(!class_exists($strClass))
33       throw new \Exception ("class do not exists: $strClass");
34     
35     static $arrObjectList = array();
36     
37     if(!isset($arrObjectList[$strClass]))
38       $arrObjectList[$strClass] = new $strClass();
39     
40     return $arrObjectList[$strClass];
41   
42   }
43
44 }