1: <?php
2:
3: namespace ModHelper;
4:
5: /**
6: * @package ModHelper
7: * @since 1.0
8: */
9: trait SingletonTrait
10: {
11: /**
12: * Create Singleton instance.
13: *
14: * @return Singleton instance
15: */
16: final public static function getInstance()
17: {
18: static $instance = null;
19:
20: if ($instance === null) {
21: $instance = new static();
22: }
23:
24: return $instance;
25: }
26:
27: /**
28: * Prevent creating Singleton instance by "new" keyword.
29: */
30: final private function __construct()
31: {
32: }
33:
34: protected function init()
35: {
36: }
37:
38: /**
39: * Prevent cloning Singleton instance.
40: */
41: final private function __clone()
42: {
43: }
44:
45: /**
46: * Prevent unserializing Singleton instance.
47: */
48: final private function __wakeup()
49: {
50: }
51: }
52: