1 | <?php |
||
16 | class Singleton extends NotConstructable |
||
|
|||
17 | { |
||
18 | /** |
||
19 | * @var array $instances |
||
20 | */ |
||
21 | protected static $instances = [ ]; |
||
22 | |||
23 | /** |
||
24 | * Prevent class from being constructed. |
||
25 | */ |
||
26 | 1 | private function __construct() |
|
29 | |||
30 | /** |
||
31 | * Get instance from $instances array. |
||
32 | * |
||
33 | * If the called class is present in the static $instances array, then return it. |
||
34 | * Otherwise, create a new copy of the class and store it in the $instances |
||
35 | * array. |
||
36 | * |
||
37 | * @param string|null $calledClass |
||
38 | * @return Object |
||
39 | */ |
||
40 | 2 | final public static function getInstance($calledClass = null) |
|
50 | |||
51 | /** |
||
52 | * Destroy |
||
53 | * |
||
54 | * @return void |
||
55 | */ |
||
56 | 1 | final public static function destroy() |
|
60 | |||
61 | /** |
||
62 | * @param $instance |
||
63 | */ |
||
64 | 1 | final public static function destroyInstance($instance) |
|
68 | } |
||
69 |