|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ComposerRequireChecker\Cli; |
|
4
|
|
|
|
|
5
|
|
|
class Options |
|
6
|
|
|
{ |
|
7
|
|
|
private $symbolWhitelist = [ |
|
8
|
|
|
'null', |
|
9
|
|
|
'true', |
|
10
|
|
|
'false', // consts |
|
11
|
|
|
'static', |
|
12
|
|
|
'self', |
|
13
|
|
|
'parent', // class hierarchy |
|
14
|
|
|
'array', |
|
15
|
|
|
'string', |
|
16
|
|
|
'int', |
|
17
|
|
|
'float', |
|
18
|
|
|
'bool', |
|
19
|
|
|
'iterable', |
|
20
|
|
|
'callable', |
|
21
|
|
|
'void', |
|
22
|
|
|
'object' // types |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
private $phpCoreExtensions = [ |
|
26
|
|
|
"Core", |
|
27
|
|
|
"date", |
|
28
|
|
|
"pcre", |
|
29
|
|
|
"Phar", |
|
30
|
|
|
"Reflection", |
|
31
|
|
|
"SPL", |
|
32
|
|
|
"standard", |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
7 |
|
public function __construct(array $actions = []) |
|
37
|
|
|
{ |
|
38
|
|
|
# For backwards compatibility, move any options without an action section to the 'set' section |
|
39
|
7 |
|
foreach ($actions as $key => $option) { |
|
40
|
6 |
|
if (in_array($key, ['set', 'append'], true)) { |
|
41
|
2 |
|
continue; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
4 |
|
if (!array_key_exists('set', $actions)) { |
|
45
|
4 |
|
$actions['set'] = []; |
|
46
|
|
|
} |
|
47
|
4 |
|
$actions['set'][$key] = $option; |
|
48
|
4 |
|
unset($actions[$key]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
7 |
|
foreach ($actions as $action => $options) { |
|
52
|
6 |
|
foreach ($options as $key => $option) { |
|
53
|
6 |
|
$methodName = $action . $this->getCamelCase($key); |
|
54
|
6 |
|
if (!method_exists($this, $methodName)) { |
|
55
|
1 |
|
throw new \InvalidArgumentException( |
|
56
|
1 |
|
$key . ' is not a known option - there is no method ' . $methodName |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
5 |
|
$this->$methodName($option); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
6 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return array |
|
66
|
|
|
*/ |
|
67
|
3 |
|
public function getSymbolWhitelist(): array |
|
68
|
|
|
{ |
|
69
|
3 |
|
return $this->symbolWhitelist; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
3 |
|
public function getPhpCoreExtensions(): array |
|
76
|
|
|
{ |
|
77
|
3 |
|
return $this->phpCoreExtensions; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param array $symbolWhitelist |
|
82
|
|
|
*/ |
|
83
|
2 |
|
public function setSymbolWhitelist(array $symbolWhitelist) |
|
84
|
|
|
{ |
|
85
|
2 |
|
$this->symbolWhitelist = $symbolWhitelist; |
|
86
|
2 |
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param array $symbolWhitelist |
|
90
|
|
|
*/ |
|
91
|
1 |
|
public function appendSymbolWhitelist(array $symbolWhitelist) |
|
92
|
|
|
{ |
|
93
|
1 |
|
$this->symbolWhitelist = array_merge($this->symbolWhitelist, $symbolWhitelist); |
|
94
|
1 |
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param array $phpCoreExtensions |
|
98
|
|
|
*/ |
|
99
|
2 |
|
public function setPhpCoreExtensions(array $phpCoreExtensions) |
|
100
|
|
|
{ |
|
101
|
2 |
|
$this->phpCoreExtensions = $phpCoreExtensions; |
|
102
|
2 |
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param array $phpCoreExtensions |
|
106
|
|
|
*/ |
|
107
|
1 |
|
public function appendPhpCoreExtensions(array $phpCoreExtensions) |
|
108
|
|
|
{ |
|
109
|
1 |
|
$this->phpCoreExtensions = array_merge($this->phpCoreExtensions, $phpCoreExtensions); |
|
110
|
1 |
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param string $string some-string |
|
114
|
|
|
* @return string someString |
|
115
|
|
|
*/ |
|
116
|
6 |
|
private function getCamelCase(string $string): string |
|
117
|
|
|
{ |
|
118
|
6 |
|
return ucfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $string)))); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|