@@ -14,27 +14,52 @@ public static function buildParameters(Event $event)
1414 {
1515 $ extras = $ event ->getComposer ()->getPackage ()->getExtra ();
1616
17- if (empty ($ extras ['incenteev-parameters ' ]['file ' ])) {
17+ if (!isset ($ extras ['incenteev-parameters ' ])) {
18+ throw new \InvalidArgumentException ('The parameter handler needs to be configured through the extra.incenteev-parameters setting. ' );
19+ }
20+
21+ $ configs = $ extras ['incenteev-parameters ' ];
22+
23+ if (!is_array ($ configs )) {
24+ throw new \InvalidArgumentException ('The extra.incenteev-parameters setting must be an array or a configuration object. ' );
25+ }
26+
27+ if (array_keys ($ configs ) !== range (0 , count ($ configs ) - 1 )) {
28+ $ configs = array ($ configs );
29+ }
30+
31+ foreach ($ configs as $ config ) {
32+ if (!is_array ($ config )) {
33+ throw new \InvalidArgumentException ('The extra.incenteev-parameters setting must be an array of configuration objects. ' );
34+ }
35+
36+ self ::processFile ($ config , $ event ->getIO ());
37+ }
38+ }
39+
40+ private static function processFile (array $ config , IOInterface $ io )
41+ {
42+ if (empty ($ config ['file ' ])) {
1843 throw new \InvalidArgumentException ('The extra.incenteev-parameters.file setting is required to use this script handler. ' );
1944 }
2045
21- $ realFile = $ extras [ ' incenteev-parameters ' ] ['file ' ];
46+ $ realFile = $ config ['file ' ];
2247
23- if (empty ($ extras [ ' incenteev-parameters ' ] ['dist-file ' ])) {
48+ if (empty ($ config ['dist-file ' ])) {
2449 $ distFile = $ realFile .'.dist ' ;
2550 } else {
26- $ distFile = $ extras [ ' incenteev-parameters ' ] ['dist-file ' ];
51+ $ distFile = $ config ['dist-file ' ];
2752 }
2853
2954 $ keepOutdatedParams = false ;
30- if (isset ($ extras [ ' incenteev-parameters ' ] ['keep-outdated ' ])) {
31- $ keepOutdatedParams = (boolean )$ extras [ ' incenteev-parameters ' ] ['keep-outdated ' ];
55+ if (isset ($ config ['keep-outdated ' ])) {
56+ $ keepOutdatedParams = (boolean ) $ config ['keep-outdated ' ];
3257 }
3358
34- if (empty ($ extras [ ' incenteev-parameters ' ] ['parameter-key ' ])) {
59+ if (empty ($ config ['parameter-key ' ])) {
3560 $ parameterKey = 'parameters ' ;
3661 } else {
37- $ parameterKey = $ extras [ ' incenteev-parameters ' ] ['parameter-key ' ];
62+ $ parameterKey = $ config ['parameter-key ' ];
3863 }
3964
4065 if (!is_file ($ distFile )) {
@@ -44,7 +69,6 @@ public static function buildParameters(Event $event)
4469 $ exists = is_file ($ realFile );
4570
4671 $ yamlParser = new Parser ();
47- $ io = $ event ->getIO ();
4872
4973 $ action = $ exists ? 'Updating ' : 'Creating ' ;
5074 $ io ->write (sprintf ('<info>%s the "%s" file.</info> ' , $ action , $ realFile ));
@@ -68,7 +92,7 @@ public static function buildParameters(Event $event)
6892 $ actualParams = (array ) $ actualValues [$ parameterKey ];
6993
7094 // Grab values for parameters that were renamed
71- $ renameMap = empty ($ extras [ ' incenteev-parameters ' ][ ' rename-map ' ]) ? array () : (array ) $ extras [ ' incenteev-parameters ' ] ['rename-map ' ];
95+ $ renameMap = empty ($ config [ ' rename-map ' ]) ? array () : (array ) $ config ['rename-map ' ];
7296 $ actualParams = array_replace ($ actualParams , self ::getRenameValues ($ renameMap , $ actualParams ));
7397
7498 if (!$ keepOutdatedParams ) {
@@ -80,7 +104,7 @@ public static function buildParameters(Event $event)
80104 }
81105 }
82106
83- $ envMap = empty ($ extras [ ' incenteev-parameters ' ][ ' env-map ' ]) ? array () : (array ) $ extras [ ' incenteev-parameters ' ] ['env-map ' ];
107+ $ envMap = empty ($ config [ ' env-map ' ]) ? array () : (array ) $ config ['env-map ' ];
84108
85109 // Add the params coming from the environment values
86110 $ actualParams = array_replace ($ actualParams , self ::getEnvValues ($ envMap ));
0 commit comments