mention replicator
[pharext/pharext.org] / app / bootstrap / config.php
index a8fe7bb0da85b2655377fef2e9fc04379f5f8b4a..e4d47729b32f92647456fd55aa632238280cdec5 100644 (file)
@@ -1,22 +1,24 @@
 <?php
 
-use merry\Config;
+namespace app;
+
+define("APP_ENVIRONMENT", getenv("APP_ENVIRONMENT") ?: "localhost");
 
 $injector->share(Config::class)
        ->define(Config::class, [
-               ":array" => parse_ini_file(__DIR__."/../config.ini", true),
-               ":section" => getenv("APP_ENVIRONMENT")
-       ])
-       ->prepare(Config::class, function(Config $config) {
-               $credentials = parse_ini_file(__DIR__."/../credentials.ini", true);
-               foreach (new Config($credentials, getenv("APP_ENVIRONMENT")) as $app => $creds) {
-                       /* one level down should suffice, i.e. $config->github->client = {id,secret,scope} */
-                       if ($creds instanceof Config) {
-                               foreach ($creds as $key => $val) {
-                                       $config->$app->$key = $val;
-                               }
-                       } else {
-                               $config->$app = $creds;
+               "+array" => function($key, $injector) {
+                       $settings = parse_ini_file(__DIR__."/../../config/app.ini", true);
+                       if (!$settings) {
+                               throw new \Exception("Could not parse settings");
                        }
+                       return $settings;
+               },
+               ":section" => APP_ENVIRONMENT
+       ])
+       ->prepare(Config::class, function($config, $injector) {
+               $credentials = parse_ini_file(__DIR__."/../../config/credentials.ini", true);
+               if (!$credentials) {
+                       throw new \Exception("Could not parse credentials");
                }
+               $config->addConfig(new Config($credentials, APP_ENVIRONMENT));
        });