From 0301681d7c0591e92b7bc904b643f4c49128d60c Mon Sep 17 00:00:00 2001 From: Francis Gilbert Date: Mon, 20 Jul 2015 20:35:43 +0200 Subject: [PATCH 1/2] Adding a way to load config directly for DI/IoC. --- src/Igorw/Silex/ConfigServiceProvider.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Igorw/Silex/ConfigServiceProvider.php b/src/Igorw/Silex/ConfigServiceProvider.php index ee70599..17def6e 100644 --- a/src/Igorw/Silex/ConfigServiceProvider.php +++ b/src/Igorw/Silex/ConfigServiceProvider.php @@ -51,6 +51,17 @@ public function register(Application $app) $this->merge($app, $config); } + public function load() + { + $config = $this->readConfig(); + + foreach ($config as $name => $value) + if ('%' === substr($name, 0, 1)) + $this->replacements[$name] = (string) $value; + + return $config; + } + public function boot(Application $app) { } From 4887edcca82ab022e570ef988b239eecd8deda6a Mon Sep 17 00:00:00 2001 From: Francis Gilbert Date: Tue, 21 Jul 2015 09:33:59 +0200 Subject: [PATCH 2/2] Adding new use in README. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 1950a9a..125527a 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,14 @@ recommended way of doing it, allowing you to define multiple environments. $env = getenv('APP_ENV') ?: 'prod'; $app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__."/../config/$env.json")); +### Loading a config file (for directly reading from config file/IoC) + +Load the config file rather than registering with application, this is for IoC in Silex. + + $env = getenv('APP_ENV') ?: 'prod'; + $provider = new \Igorw\Silex\ConfigServiceProvider(__DIR__."/../config/$env.json")); + return $provider->load(); + Now you can specify a `prod` and a `dev` environment. **config/prod.json**