|
123456789101112131415161718192021222324252627282930313233343536 |
- <?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);
- }*/
-
- final public static function getInstance(): self
- {
- $c = get_called_class();
-
- if (!isset(self::$instances[$c])) {
- self::$instances[$c] = new $c;
-
- if(in_array(ManagerInterface::class, class_implements(self::$instances[$c]))) {
- self::$instances[$c]->initContainer();
- }
-
- if(in_array(ServiceInterface::class, class_implements(self::$instances[$c]))) {
- self::$instances[$c]->loadDependencies();
- }
- }
-
- return self::$instances[$c];
- }
- }
|