|
|
|
|
@ -3,24 +3,27 @@
|
|
|
|
|
namespace jrosset\Singleton;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Classe d'implémentation d'un Singleton (création via le constructeur)
|
|
|
|
|
* Trait for singleton design pattern
|
|
|
|
|
*/
|
|
|
|
|
trait TSingleton {
|
|
|
|
|
/**
|
|
|
|
|
* @var static|null L'instance. Null si pas encore créée
|
|
|
|
|
* @var static|null The current instance. Null if not already created
|
|
|
|
|
* @noinspection PhpDocFieldTypeMismatchInspection
|
|
|
|
|
*/
|
|
|
|
|
private static ?self $singleton_instance;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initialise l'instance'
|
|
|
|
|
* Initialize the instance
|
|
|
|
|
*/
|
|
|
|
|
protected function __construct () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Accès à l'instance du Singleton
|
|
|
|
|
* Get the instance
|
|
|
|
|
*
|
|
|
|
|
* Si l'instance n'a pas encore été créée, elle le sera automatiquement
|
|
|
|
|
* If the instance is not already created then create it
|
|
|
|
|
*
|
|
|
|
|
* @return static L'unique instance du Singleton
|
|
|
|
|
* @return static The instance
|
|
|
|
|
*/
|
|
|
|
|
public static final function getInstance (): self {
|
|
|
|
|
if (!isset(self::$singleton_instance)) {
|
|
|
|
|
|