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.

AbstractSingleton.php 851B

пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
123456789101112131415161718192021222324252627282930313233343536
  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. self::$instances[$c]->initContainer();
  20. }
  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. }