public function __construct($root_directory) { //init Pimple parent::__construct(); //make sure root has a trailing slash if (substr($root_directory, -1) !== '/') { $root_directory .= '/'; } $this->root_directory = $root_directory; $this['config.cache'] = function () { $cache_file = $this->root_directory . 'storage/cache/config-' . $this->env . '.php'; return new ConfigCache($cache_file); }; $this['config'] = function () { $this->env_locked = true; if ($this->cache_enabled) { $cache = $this['config.cache']; if ($cache->isSaved()) { return $cache->getConfig(); } } $manager = $this['config.manager']; //load configuration for each module foreach ($this->modules as $module) { $module->loadConfig($manager); } //then for the application (default is config/neptune.yml). $this->loadConfig($manager); $config = $manager->getConfig(); if ($this->cache_enabled) { $cache->save($config, $manager->getCacheMessage()); } return $config; }; $this['config.manager'] = function ($neptune) { $manager = new ConfigManager(); $manager->addLoader(new Loader\YamlLoader()); $manager->addLoader(new Loader\JsonLoader()); $manager->addLoader(new Loader\PhpLoader()); $manager->addProcessor(new Processor\OptionsProcessor()); $manager->addProcessor(new Processor\EnvironmentProcessor($neptune)); $manager->addProcessor(new Processor\ReferenceProcessor()); return $manager; }; $this['dispatcher'] = function () { $dispatcher = new EventDispatcher(); foreach ($this->getTaggedServices('neptune.dispatcher.subscribers') as $subscriber) { $dispatcher->addSubscriber($subscriber); } return $dispatcher; }; $this['request_stack'] = function () { return new RequestStack(); }; $this['kernel'] = function () { return new HttpKernel($this['dispatcher'], $this['resolver'], $this['request_stack']); }; }
public function testVariablesCanBeUsedForReferences() { $manager = new ConfigManager(); $manager->loadValues(['log_path' => '%ROOT%/logs/%ENV%.log']); $manager->addProcessor(new ReferenceProcessor()); $manager->addProcessor($this->processor); $this->neptune->expects($this->once())->method('getRootDirectory')->will($this->returnValue('/path/to/app')); $this->neptune->expects($this->once())->method('getEnv')->will($this->returnValue('dev')); $this->assertSame('/path/to/app/logs/dev.log', $manager->getConfig()->get('log_path')); }