Add an interface for singleton requirement

1.x v1.1.0
Julien Rosset 4 years ago
parent 70a0f14c26
commit e666d93f28

@ -0,0 +1,17 @@
<?php
namespace jrosset\Singleton;
/**
* Interface for class that must implements a singleton
*/
interface ISingleton {
/**
* Get the instance
*
* If the instance is not already created then create it
*
* @return static The instance
*/
public static function getInstance (): self;
}

@ -3,7 +3,9 @@
namespace jrosset\Singleton;
/**
* Trait for singleton design pattern
* Trait for simple singleton
*
* Initialization through the constructor
*/
trait TSingleton {
/**

@ -3,9 +3,10 @@
require_once __DIR__ . '/../vendor/autoload.php';
use jrosset\Singleton\ISingleton;
use jrosset\Singleton\TSingleton;
class Test {
class Test implements ISingleton {
use TSingleton;
private int $cpt = 0;

Loading…
Cancel
Save