公開ライブラリがあり、1 つの PHP プロセスに 1 つのインスタンスしか持てないクラスがあるので、Singleton です。問題は、このクラスの初期化にはいくつかの構成引数が必要であり、それらをクラス コンストラクターに渡すための適切な問題が見つからないことです。
私が見つけた唯一の問題は次のとおりです。
public static function init($params) {
if(self::$instance) {
throw new Exception(__CLASS__ . ' already initialized');
}
$class = __CLASS__;
self::$instance = new $class($params);
}
public static function getInstance() {
if(!self::$instance) {
throw new Exception(__CLASS__ . ' is not initialized');
}
return self::$instance;
}
でも、そんなにいいとは思いません。他に何かアイデアはありますか?
ありがとう!