Skip to content

Commit 10285a3

Browse files
committed
Added ability to customise the 'parameters' key.
1 parent e99fbef commit 10285a3

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

ScriptHandler.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public static function buildParameters(Event $event)
3131
$keepOutdatedParams = (boolean)$extras['incenteev-parameters']['keep-outdated'];
3232
}
3333

34+
if (empty($extras['incenteev-parameters']['parameter-key'])) {
35+
$parameterKey = 'parameters';
36+
} else {
37+
$parameterKey = $extras['incenteev-parameters']['parameter-key'];
38+
}
39+
3440
if (!is_file($distFile)) {
3541
throw new \InvalidArgumentException(sprintf('The dist file "%s" does not exist. Check your dist-file config or create it.', $distFile));
3642
}
@@ -45,21 +51,21 @@ public static function buildParameters(Event $event)
4551

4652
// Find the expected params
4753
$expectedValues = $yamlParser->parse(file_get_contents($distFile));
48-
if (!isset($expectedValues['parameters'])) {
54+
if (!isset($expectedValues[$parameterKey])) {
4955
throw new \InvalidArgumentException('The dist file seems invalid.');
5056
}
51-
$expectedParams = (array) $expectedValues['parameters'];
57+
$expectedParams = (array) $expectedValues[$parameterKey];
5258

5359
// find the actual params
54-
$actualValues = array('parameters' => array());
60+
$actualValues = array($parameterKey => array());
5561
if ($exists) {
5662
$existingValues = $yamlParser->parse(file_get_contents($realFile));
5763
if (!is_array($existingValues)) {
5864
throw new \InvalidArgumentException(sprintf('The existing "%s" file does not contain an array', $realFile));
5965
}
6066
$actualValues = array_merge($actualValues, $existingValues);
6167
}
62-
$actualParams = (array) $actualValues['parameters'];
68+
$actualParams = (array) $actualValues[$parameterKey];
6369

6470
if (!$keepOutdatedParams) {
6571
// Remove the outdated params
@@ -77,7 +83,7 @@ public static function buildParameters(Event $event)
7783

7884
$actualParams = self::getParams($io, $expectedParams, $actualParams);
7985

80-
file_put_contents($realFile, "# This file is auto-generated during the composer install\n" . Yaml::dump(array('parameters' => $actualParams)));
86+
file_put_contents($realFile, "# This file is auto-generated during the composer install\n" . Yaml::dump(array($parameterKey => $actualParams)));
8187
}
8288

8389
private static function getEnvValues(array $envMap)

0 commit comments

Comments
 (0)