私は2つのクラス(EnvironmentとConfigurationReader)を定義しました。両方とも共有依存として登録されています。共有サービスを取得する最大再帰
Environmentクラスは現在の環境を取得しようとしますが、このためにConfigurationReaderを介して環境設定ファイルを読み込む必要があります。
シーケンス図である。
クラスは以下のとおりです。
class Environment
{
...
public function resolve()
{
$config = DI::getDefault()->getCfg();
$config->getValue('pepe', 'db_name');
}
...
}
class ConfigurationReader
{
...
public function getValue($aConfig, $aKey)
{
$path = $this->getFile($aConfig);
}
protected function getFile($aConfig)
{
$env = DI::getDefault()->getEnv();
$path = 'config/' . $env->getShortName() . '/' . $aConfig . '.yml';
return $path;
}
...
}
とのindex.phpに登録して作成されますので、
...
$di = new FactoryDefault();
$di->setShared('env', function() use ($di) {
$env = new Services\Environment($di);
$env->resolve();
return $env;
});
$di->setShared('cfg', function() use ($di) {
return new Services\ConfigurationReader($di);
});
$di->getShared('cfg');
$di->getShared('env');
...
、PHP $config = DI::getDefault()->getCfg();
でクラッシュし、
PHP Fatal error: Maximum recursion depth exceeded
$ diをあなたのConfigurationReaderクラスに渡していますが、コンストラクタで何をやっていますか? –