|
1234567891011121314151617181920212223242526272829303132333435 |
- <?php
-
- namespace common\logic;
-
- 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];
- }
- }
|