-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathHelper.php
More file actions
104 lines (97 loc) · 3.01 KB
/
Copy pathHelper.php
File metadata and controls
104 lines (97 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* This file is part of CaptainHook.
*
* (c) Sebastian Feldmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CaptainHook\App\Config;
/**
* Config Helper
*
* @package CaptainHook
* @author Sebastian Feldmann <[email protected]>
* @link https://github.com/captainhook-git/captainhook
* @since Class available since Release 5.28.2
* @internal
*/
final class Helper
{
/**
* Create plugin configs from the settings array
*
* @param array<string, mixed> $settings
* @return array<string, \CaptainHook\App\Config\Plugin>
*/
public static function createPluginConfigs(array $settings): array
{
/* @var array<int, array<string, mixed>> $pluginSettings */
$pluginSettings = $settings['plugins'] ?? [];
unset($settings['plugins']);
$plugins = [];
foreach ($pluginSettings as $plugin) {
$name = (string) $plugin['plugin'];
$options = isset($plugin['options']) && is_array($plugin['options']) ? $plugin['options'] : [];
$plugins[$name] = new Plugin($name, $options);
}
return $plugins;
}
/**
* Clean up legacy run configuration settings
*
* @param array<string, mixed> $settings
* @return array<string, mixed>
*/
public static function cleanupRunConfig(array $settings): array
{
// extract the legacy settings
$settingsToMove = [
Settings::RUN_MODE,
Settings::RUN_EXEC,
Settings::RUN_PATH,
Settings::RUN_GIT
];
$config = [];
foreach ($settingsToMove as $setting) {
if (!empty($settings[$setting])) {
$config[substr($setting, 4)] = $settings[$setting];
}
unset($settings[$setting]);
}
// make sure the new run configuration supersedes the legacy settings
if (isset($settings['run']) && is_array($settings['run'])) {
$config = array_merge($config, $settings['run']);
}
$settings['run'] = $config;
return $settings;
}
/**
* Extract the base settings from the given settings array
*
* @param array<string, mixed> $settings
* @return array<string, mixed>
*/
public static function extractBaseSettings(array $settings): array
{
$baseSettings = [
Settings::ALLOW_FAILURE,
Settings::BOOTSTRAP,
Settings::COLORS,
Settings::GIT_DIR,
Settings::FAIL_ON_FIRST_ERROR,
Settings::VERBOSITY,
Settings::INCLUDES,
Settings::INCLUDES_LEVEL,
Settings::PHP_PATH,
];
$config = [];
foreach ($baseSettings as $setting) {
if (isset($settings[$setting])) {
$config[$setting] = $settings[$setting];
}
}
return $config;
}
}