| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class Singleton |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace LearnPress\Helpers; |
| 8 |
|
| 9 |
trait Singleton { |
| 10 |
private static $instance = null; |
| 11 |
final public static function instance(): self { |
| 12 |
if ( is_null( static::$instance ) ) { |
| 13 |
static::$instance = new static(); |
| 14 |
} |
| 15 |
|
| 16 |
return static::$instance; |
| 17 |
} |
| 18 |
|
| 19 |
final private function __construct() { |
| 20 |
$this->init(); |
| 21 |
} |
| 22 |
|
| 23 |
abstract public function init(); |
| 24 |
} |
| 25 |
|