【发布时间】:2013-04-05 11:18:02
【问题描述】:
在 ZF2 应用程序中,我有一些配置,即: 1. 需要根据环境而有所不同; 2. 特定于具体模块。我正在像here 描述的那样使用它:
global.php & local.php
return array(
...
'modules' => array(
'Cache' => array(
'ttl' => 1, // 1 second
)
)
...
);
模块类
Module {
...
public function getServiceConfig() {
try {
return array (
'factories' => array(
'Zend\Cache\Adapter\MemcachedOptions' => function ($serviceManager) {
return new MemcachedOptions(array(
'ttl' => $this->getConfig()['modules']['Cache']['ttl'],
...
));
},
...
)
);
}
...
}
...
}
它工作得很好,但我相信,应该通过模块中的一个中心位置访问模块特定设置——Module 类的getConfig() 方法。像这样:
class Module {
public function getConfig() {
$moduleConfig = include __DIR__ . '/config/module.config.php';
$application = $this->getApplicationSomehow(); // <-- how?
$applicationModuleConfig = $application->getConfig()['modules'][__NAMESPACE__];
$config = array_merge($moduleConfig, $applicationModuleConfig);
return $config;
}
...
public function getServiceConfig() {
try {
return array (
'factories' => array(
'Zend\Cache\Adapter\MemcachedOptions' => function ($serviceManager) {
return new MemcachedOptions(array(
'ttl' => $serviceManager->get('Config')['modules']['Cache']['ttl'],
...
));
},
...
)
);
}
...
}
...
}
问题是,我不明白如何访问模块的getConfig() 中的 global.php/local.php 配置。我该怎么做?
【问题讨论】:
标签: configuration zend-framework2 config configuration-files