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']); }; }