/** * ビルド */ public static function build($name, $dir, $env = ['all', 'dev'], $useCache = true) { $name = $name . '.' . implode('.', $env); if ($useCache) { $file = Context::singleton()->getCachePath("config", $name); if (file_exists($file)) { $c = self::restore($name); $c->_cache = true; return $c; } } $c = new Configuration($name); $c->loadDir($dir, null, $env); $c->_cache = false; $c->save(); return $c; }
public function __construct($name, SystemContext $context, $dir) { $this->_context = new Context($context, $dir); // ConfigPathを設定 $configPath = $this->_context->getFilePath('config'); // Configを作成 $this->_config = Configuration::build('module.' . $name, $configPath, $context->getVal('env'), $useCache = false); // AutoLoader $ns = $this->_config->read('namespace', $context->getService('config')->read('module.namespace') . '\\' . ucfirst($name)); $this->_context->setVal('ns', $ns); $context->getService('autoloader')->register([$ns . '\\Controller' => $this->_context->getFilePath('controller'), $this->_context->getFilePath('lib')]); }
/** * セットアップ */ public function configure($name, $root, $env, $options) { $this->_root = realpath($root); $options['root'] = $this->_root; $options['env'] = $env; $options['name'] = $name; $this->Context()->setVal($options); // CachePathを設定 $this->Context()->setCachePath($this->getFilePath($this->Context()->getVal('cache', '/tmp/cache'))); // ConfigPathを設定 $configPath = $this->getFilePath($this->Context()->getVal('config', 'config')); // Configを作成 $this->_config = Configuration::build($name, $configPath, $env, $useCache = false); return $this; }
public function testBuild() { $c = Configuration::build('hoge', TEST_DIR . '/config/test', ['all', 'dev', 'hoge']); $this->assertEquals($c->read('database.connection.default.user'), 'hoge'); }