You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
943B

  1. <?php
  2. namespace common\logic;
  3. abstract class AbstractSingleton
  4. {
  5. private static $instances = array();
  6. final private function __construct()
  7. {
  8. }
  9. /*final public function __clone()
  10. {
  11. trigger_error("Le clonage n'est pas autorisé.", E_USER_ERROR);
  12. }*/
  13. final public static function getInstance(): self
  14. {
  15. $c = get_called_class();
  16. if (!isset(self::$instances[$c])) {
  17. self::$instances[$c] = new $c;
  18. if(in_array(ManagerInterface::class, class_implements(self::$instances[$c]))
  19. || in_array(ModuleInterface::class, class_implements(self::$instances[$c]))) {
  20. self::$instances[$c]->initContainer();
  21. }
  22. if(in_array(ServiceInterface::class, class_implements(self::$instances[$c]))) {
  23. self::$instances[$c]->loadDependencies();
  24. }
  25. }
  26. return self::$instances[$c];
  27. }
  28. }