diff --git a/Processor.php b/Processor.php index 6dc208f..2b8988e 100644 --- a/Processor.php +++ b/Processor.php @@ -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)); diff --git a/Tests/fixtures/testcases/environment_auto/dist.yml b/Tests/fixtures/testcases/environment_auto/dist.yml new file mode 100644 index 0000000..72e554a --- /dev/null +++ b/Tests/fixtures/testcases/environment_auto/dist.yml @@ -0,0 +1,6 @@ +parameters: + boolean: false + another: ~ + nested: nested + foo_baz: '' + foo.baz: '' diff --git a/Tests/fixtures/testcases/environment_auto/expected.yml b/Tests/fixtures/testcases/environment_auto/expected.yml new file mode 100644 index 0000000..7164a11 --- /dev/null +++ b/Tests/fixtures/testcases/environment_auto/expected.yml @@ -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 diff --git a/Tests/fixtures/testcases/environment_auto/setup.yml b/Tests/fixtures/testcases/environment_auto/setup.yml new file mode 100644 index 0000000..811f016 --- /dev/null +++ b/Tests/fixtures/testcases/environment_auto/setup.yml @@ -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]}' diff --git a/Tests/fixtures/testcases/environment_auto_with_prefix/dist.yml b/Tests/fixtures/testcases/environment_auto_with_prefix/dist.yml new file mode 100644 index 0000000..72e554a --- /dev/null +++ b/Tests/fixtures/testcases/environment_auto_with_prefix/dist.yml @@ -0,0 +1,6 @@ +parameters: + boolean: false + another: ~ + nested: nested + foo_baz: '' + foo.baz: '' diff --git a/Tests/fixtures/testcases/environment_auto_with_prefix/expected.yml b/Tests/fixtures/testcases/environment_auto_with_prefix/expected.yml new file mode 100644 index 0000000..7164a11 --- /dev/null +++ b/Tests/fixtures/testcases/environment_auto_with_prefix/expected.yml @@ -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 diff --git a/Tests/fixtures/testcases/environment_auto_with_prefix/setup.yml b/Tests/fixtures/testcases/environment_auto_with_prefix/setup.yml new file mode 100644 index 0000000..b10829d --- /dev/null +++ b/Tests/fixtures/testcases/environment_auto_with_prefix/setup.yml @@ -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]}'