From 005f1e329289792892929a714a4380be8f635130 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 18 Jun 2018 20:21:31 +0200 Subject: [PATCH] app/library/Services.php: make config service abit more generic (loading any number of files). --- app/library/Services.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/app/library/Services.php b/app/library/Services.php index 19b1ccb..60da7ba 100644 --- a/app/library/Services.php +++ b/app/library/Services.php @@ -59,14 +59,27 @@ class Services extends DiDefault protected function _initSharedConfig() { - $config = new Config(APP_PATH . '/app/config/conf.app.yml'); + // All config files used by the application. + // These will be compiled into a single config object. + // + // The priority is files defined AFTER another + // will override settings if there a multiple keys. + $files = array( + 'conf.app.yml', + 'conf.local.yml' + ); - try { - $local = new Config(APP_PATH . '/app/config/conf.local.yml'); + $basePath = APP_PATH . '/app/config/'; - $config->merge($local); - } catch(Phalcon\Config\Exception $e) { - // Sometime went wrong. + $config = new \Phalcon\Config(); + + foreach ($files as $file) { + + try { + $config->merge(new Config($basePath . $file)); + } catch(\Phalcon\Config\Exception $e) { + // Sometime went wrong. Log here? + } } return $config;