Skip to content

Commit 9f1e09a

Browse files
committed
Merge pull request #53 from lucascourot/patch-1
Fix small typo in the Readme
2 parents f6b9861 + 056c6c8 commit 9f1e09a

File tree

12 files changed

+119
-2
lines changed

12 files changed

+119
-2
lines changed

Processor.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,18 @@ private function processParams(array $config, array $expectedParams, array $actu
9999
$actualParams = array_intersect_key($actualParams, $expectedParams);
100100
}
101101

102-
$envMap = empty($config['env-map']) ? array() : (array) $config['env-map'];
102+
$envMap = array();
103+
// Add the params coming from the environment values
104+
if (!empty($config['env-map'])) {
105+
// Hydrate env-map from dist file
106+
if ('auto' === $config['env-map']) {
107+
array_walk($expectedParams, function($v, $k) use (&$envMap) {
108+
$envMap[$k] = strtoupper($k);
109+
});
110+
} else {
111+
$envMap = (array) $config['env-map'];
112+
}
113+
}
103114

104115
// Add the params coming from the environment values
105116
$actualParams = array_replace($actualParams, $this->getEnvValues($envMap));

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This tool allows you to manage your ignored parameters when running a composer
44
install or update. It works when storing the parameters in a Yaml file under
5-
a a single top-level key (named ``parameters`` by default). Other keys are
5+
a single top-level key (named ``parameters`` by default). Other keys are
66
copied without change.
77

88
[![Build Status](https://travis-ci.org/Incenteev/ParameterHandler.png)](https://travis-ci.org/Incenteev/ParameterHandler)
@@ -122,6 +122,35 @@ As environment variables can only be strings, they are also parsed as inline
122122
Yaml values to allows specifying ``null``, ``false``, ``true`` or numbers
123123
easily.
124124

125+
## Using same names for parameters and environment variables
126+
127+
As an alternative, you can set environment variables with the same uppercased
128+
name of your dist parameters and use ``"env-map": "auto"`` to get an auto mapping.
129+
``my_first_param`` parameter will map ``MY_FIRST_PARAM`` environment variable.
130+
131+
Given this ``parameters.yml.dist`` file:
132+
133+
```yaml
134+
# parameters.yml.dist
135+
136+
parameters:
137+
my_first_param: "some value"
138+
my_second_param: "another value"
139+
140+
```
141+
142+
Following settings will produce the same result as previous example:
143+
144+
```json
145+
{
146+
"extra": {
147+
"incenteev-parameters": {
148+
"env-map": "auto"
149+
}
150+
}
151+
}
152+
```
153+
125154
### Renaming parameters
126155

127156
If you are renaming a parameter, the new key will be set according to the usual
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
ic_test_bool: false
3+
another: test
4+
ic_test_nested: nested
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file is auto-generated during the composer install
2+
parameters:
3+
ic_test_bool: true
4+
ic_test_nested:
5+
foo: env_foo
6+
bar:
7+
- env
8+
- test
9+
- null
10+
another: null
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
title: Values provided by the environment are not asked interactively
2+
3+
config:
4+
env-map: 'auto'
5+
6+
environment:
7+
IC_TEST_BOOL: 'true'
8+
IC_TEST_NESTED: '{foo: env_foo, bar: [env, test, null]}'
9+
10+
interactive: true
11+
12+
requested_params:
13+
another:
14+
default: test
15+
input: 'null'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
ic_test_foo: bar
3+
ic_test_bool: false
4+
another: ~
5+
ic_test_nested:
6+
foo: bar
7+
bar: baz
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is auto-generated during the composer install
2+
parameters:
3+
ic_test_foo: foobar
4+
ic_test_bool: true
5+
another: null
6+
ic_test_nested:
7+
foo: env_foo
8+
bar:
9+
- env
10+
- test
11+
- null
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
title: Environment variables are used over dist file defaults
2+
3+
config:
4+
env-map: 'auto'
5+
6+
environment:
7+
IC_TEST_BOOL: 'true'
8+
IC_TEST_FOO: 'foobar'
9+
IC_TEST_NESTED: '{foo: env_foo, bar: [env, test, null]}'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
ic_test_new: bar
3+
new2: new2
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file is auto-generated during the composer install
2+
parameters:
3+
old: old_value
4+
old2: old_value2

0 commit comments

Comments
 (0)