Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load Config directly #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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