2018-11-12 16:58:56 +01:00
|
|
|
<?php
|
|
|
|
|
2018-11-19 14:27:42 +01:00
|
|
|
/**
|
|
|
|
* Trait SingletonTrait
|
|
|
|
* This trait helps implementing singleton classes
|
|
|
|
* It must be used on each class in a hierarchy that needs to be a singleton
|
|
|
|
*/
|
2018-11-12 16:58:56 +01:00
|
|
|
trait SingletonTrait
|
|
|
|
{
|
2018-11-19 14:27:42 +01:00
|
|
|
protected static $instance;
|
2018-11-12 16:58:56 +01:00
|
|
|
|
2018-11-19 14:27:42 +01:00
|
|
|
private function __construct()
|
2018-11-12 16:58:56 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getInstance()
|
|
|
|
{
|
|
|
|
if (!isset(static::$instance)) {
|
|
|
|
static::$instance = new static();
|
|
|
|
}
|
|
|
|
return static::$instance;
|
|
|
|
}
|
|
|
|
}
|