|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ComposerRequireChecker\Cli; |
|
4
|
|
|
|
|
5
|
|
|
class Options |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
private $symbolWhitelist = [ |
|
9
|
|
|
'null', 'true', 'false', // consts |
|
10
|
|
|
'static', 'self', 'parent', // class hierarchy |
|
11
|
|
|
'array', 'string', 'int', 'float', 'bool' // types |
|
12
|
|
|
]; |
|
13
|
|
|
|
|
14
|
|
|
private $phpCoreExtensions = [ |
|
15
|
|
|
"Core", |
|
16
|
|
|
"date", |
|
17
|
|
|
"pcre", |
|
18
|
|
|
"Reflection", |
|
19
|
|
|
"SPL", |
|
20
|
|
|
"standard", |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
public function __construct(array $options = []) |
|
25
|
|
|
{ |
|
26
|
|
|
foreach ($options as $key => $option) { |
|
27
|
|
|
$methodName = 'set'.$this->getCamelCase($key); |
|
28
|
|
|
if(!method_exists($this, $methodName)) { |
|
29
|
|
|
throw new \InvalidArgumentException($key . ' is not a known option - there is no method ' . $methodName); |
|
30
|
|
|
} |
|
31
|
|
|
$this->$methodName($option); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return array |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getSymbolWhitelist() : array |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->symbolWhitelist; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getPhpCoreExtensions() : array |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->phpCoreExtensions; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param array $symbolWhitelist |
|
53
|
|
|
*/ |
|
54
|
|
|
public function setSymbolWhitelist(array $symbolWhitelist) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->symbolWhitelist = $symbolWhitelist; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param array $phpCoreExtensions |
|
61
|
|
|
*/ |
|
62
|
|
|
public function setPhpCoreExtensions(array $phpCoreExtensions) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->phpCoreExtensions = $phpCoreExtensions; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param string $string some-string |
|
69
|
|
|
* @return string someString |
|
70
|
|
|
*/ |
|
71
|
|
|
private function getCamelCase(string $string) : string |
|
72
|
|
|
{ |
|
73
|
|
|
return ucfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $string)))); |
|
74
|
|
|
} |
|
75
|
|
|
} |