| 1 | <?php | ||
| 17 | trait Singleton | ||
| 18 | { | ||
| 19 | /** | ||
| 20 | * @var static | ||
| 21 | */ | ||
| 22 | protected static $_instance; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * Get the instance. | ||
| 26 | * | ||
| 27 | * @return static | ||
| 28 | */ | ||
| 29 | 3 | final public static function getInstance() | |
| 37 | |||
| 38 | /** | ||
| 39 | * Swap the instance to another. | ||
| 40 | * | ||
| 41 | * @param mixed $instance | ||
| 42 | */ | ||
| 43 | 1 | final public static function swap($instance) | |
| 47 | |||
| 48 | /** | ||
| 49 | * Make __construct private to avoid new the object. | ||
| 50 | */ | ||
| 51 | 1 | private function __construct() | |
| 54 | |||
| 55 | /** | ||
| 56 | * Disable clone. | ||
| 57 | */ | ||
| 58 | private function __clone() | ||
| 61 | } | ||
| 62 |