Skip to content

Automapping environment variables #86

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

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 11 additions & 1 deletion Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,17 @@ private function processParams(array $config, array $expectedParams, array $actu
$actualParams = array_intersect_key($actualParams, $expectedParams);
}

$envMap = empty($config['env-map']) ? array() : (array) $config['env-map'];
$envMap = array();
if (!empty($config['env-map'])) {
if ('auto' === $config['env-map']) {
$envPrefix = !empty($config['env-prefix']) ? $config['env-prefix'] : '';
foreach ($expectedParams as $key => $value) {
$envMap[$key] = $envPrefix.strtoupper(str_replace('.', '__', $key));
}
} else {
$envMap = (array)$config['env-map'];
}
}

// Add the params coming from the environment values
$actualParams = array_replace($actualParams, $this->getEnvValues($envMap));
Expand Down
6 changes: 6 additions & 0 deletions Tests/fixtures/testcases/environment_auto/dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
boolean: false
another: ~
nested: nested
foo_baz: ''
foo.baz: ''
12 changes: 12 additions & 0 deletions Tests/fixtures/testcases/environment_auto/expected.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is auto-generated during the composer install
parameters:
boolean: true
another: null
nested:
foo: env_foo
bar:
- env
- test
- null
foo_baz: foo_baz
foo.baz: foo.baz
10 changes: 10 additions & 0 deletions Tests/fixtures/testcases/environment_auto/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: Automatically mapped values provided by the environment

config:
env-map: 'auto'

environment:
BOOLEAN: 'true'
FOO_BAZ: 'foo_baz'
FOO__BAZ: 'foo.baz'
NESTED: '{foo: env_foo, bar: [env, test, null]}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
boolean: false
another: ~
nested: nested
foo_baz: ''
foo.baz: ''
12 changes: 12 additions & 0 deletions Tests/fixtures/testcases/environment_auto_with_prefix/expected.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is auto-generated during the composer install
parameters:
boolean: true
another: null
nested:
foo: env_foo
bar:
- env
- test
- null
foo_baz: foo_baz
foo.baz: foo.baz
11 changes: 11 additions & 0 deletions Tests/fixtures/testcases/environment_auto_with_prefix/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: Automatically mapped values provided by the environment with configured prefix

config:
env-map: 'auto'
env-prefix: 'SYMFONY__'

environment:
SYMFONY__BOOLEAN: 'true'
SYMFONY__FOO_BAZ: 'foo_baz'
SYMFONY__FOO__BAZ: 'foo.baz'
SYMFONY__NESTED: '{foo: env_foo, bar: [env, test, null]}'