|
- <?php
-
- namespace domain\_;
-
- abstract class AbstractSingleton
- {
- private static $instances = array();
-
- final private function __construct()
- {
- }
-
- /*final public function __clone()
- {
- trigger_error("Le clonage n'est pas autorisé.", E_USER_ERROR);
- }*/
-
- /**
- * @return $this
- */
- final public static function getInstance(): self
- {
- $c = get_called_class();
-
- if (!isset(self::$instances[$c])) {
- self::$instances[$c] = new $c;
-
- if(in_array(ServiceInterface::class, class_implements(self::$instances[$c]))) {
- self::$instances[$c]->loadDependencies();
- }
- }
-
- return self::$instances[$c];
- }
- }
|