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.

36 line
726B

  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. /**
  14. * @return $this
  15. */
  16. final public static function getInstance(): self
  17. {
  18. $c = get_called_class();
  19. if (!isset(self::$instances[$c])) {
  20. self::$instances[$c] = new $c;
  21. if(in_array(ServiceInterface::class, class_implements(self::$instances[$c]))) {
  22. self::$instances[$c]->loadDependencies();
  23. }
  24. }
  25. return self::$instances[$c];
  26. }
  27. }