Multiton.php 558 B

1234567891011121314151617181920212223242526
  1. <?php
  2. /**
  3. * 多例模式
  4. * Created by: PhpStorm
  5. * User: lytian
  6. * Date: 2019/10/31
  7. * Time: 14:38
  8. */
  9. namespace app\main\InternalInterface;
  10. abstract class Multiton
  11. {
  12. private static $instances = [];
  13. public static function getInstance()
  14. {
  15. $key = get_called_class() . serialize(func_get_args());
  16. if (!isset(self::$instances[$key])) {
  17. $rc = new \ReflectionClass(get_called_class());
  18. self::$instances[$key] = $rc->newInstanceArgs(func_get_args());
  19. }
  20. return self::$instances[$key];
  21. }
  22. }