You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
723 B
PHP
35 lines
723 B
PHP
<?php
|
|
|
|
namespace jrosset\Singleton;
|
|
|
|
/**
|
|
* Default implementation for singleton
|
|
*
|
|
* Initialization through the constructor
|
|
*
|
|
* @see ISingleton for interface
|
|
*/
|
|
trait TSingleton {
|
|
/**
|
|
* @var static|null The current instance. Null if not already created
|
|
* @noinspection PhpDocFieldTypeMismatchInspection
|
|
*/
|
|
private static ?self $singletonInstance;
|
|
|
|
/**
|
|
* Initialize the instance
|
|
*/
|
|
protected function __construct () {
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public static final function getInstance (): static {
|
|
if (!isset(self::$singletonInstance)) {
|
|
self::$singletonInstance = new static();
|
|
}
|
|
|
|
return self::$singletonInstance;
|
|
}
|
|
} |