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** 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) { }