| 1 |
<?php |
| 2 |
|
| 3 |
namespace OPTN\Includes\Traits; |
| 4 |
|
| 5 |
trait Singleton { |
| 6 |
private static $instance = null; |
| 7 |
|
| 8 |
/** |
| 9 |
* Constructor |
| 10 |
* |
| 11 |
* @return void |
| 12 |
*/ |
| 13 |
protected function __construct() {} |
| 14 |
|
| 15 |
final public static function get_instance() { |
| 16 |
if ( null === static::$instance ) { |
| 17 |
static::$instance = new static(); |
| 18 |
} |
| 19 |
return static::$instance; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Prevent cloning. |
| 24 |
*/ |
| 25 |
private function __clone() {} |
| 26 |
} |
| 27 |
|