Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
11 changes: 11 additions & 0 deletions src/Igorw/Silex/ConfigServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down