| Total Complexity | 6 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | trait SingletonTrait |
||
| 15 | { |
||
| 16 | protected static $instance; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param string $instanceKey |
||
| 20 | * |
||
| 21 | * @return SingletonTrait |
||
| 22 | * |
||
| 23 | * @throws CSESingletonException |
||
| 24 | */ |
||
| 25 | public static function getInstance(string $instanceKey = ''): self |
||
| 26 | { |
||
| 27 | $instanceKey = empty($instanceKey) ? __CLASS__ : $instanceKey; |
||
| 28 | |||
| 29 | // instance exist |
||
| 30 | if (empty(self::$instance[$instanceKey])) { |
||
| 31 | $reflection = new \ReflectionClass(__CLASS__); |
||
| 32 | $arg = func_get_args(); |
||
| 33 | array_shift($arg); |
||
| 34 | self::$instance[$instanceKey] = $reflection->newInstanceArgs($arg); |
||
| 35 | } |
||
| 36 | |||
| 37 | return self::$instance[$instanceKey]; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @throws CSESingletonException |
||
| 42 | */ |
||
| 43 | final public function __clone() |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @throws CSESingletonException |
||
| 50 | */ |
||
| 51 | final public function __sleep() |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @throws CSESingletonException |
||
| 58 | */ |
||
| 59 | final public function __wakeup() |
||
| 62 | } |
||
| 63 | } |