|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace ApiGen\Configuration; |
|
4
|
|
|
|
|
5
|
|
|
use ApiGen\Contracts\Configuration\ConfigurationInterface; |
|
6
|
|
|
|
|
7
|
|
|
final class Configuration implements ConfigurationInterface |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var mixed[] |
|
11
|
|
|
*/ |
|
12
|
|
|
private $options; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var ConfigurationOptionsResolver |
|
16
|
|
|
*/ |
|
17
|
|
|
private $configurationOptionsResolver; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct(ConfigurationOptionsResolver $configurationOptionsResolver) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->configurationOptionsResolver = $configurationOptionsResolver; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param mixed[] $options |
|
26
|
|
|
* @return mixed[] |
|
27
|
|
|
*/ |
|
28
|
|
|
public function resolveOptions(array $options): array |
|
29
|
|
|
{ |
|
30
|
|
|
$options = $this->unsetConsoleOptions($options); |
|
31
|
|
|
return $this->options = $this->configurationOptionsResolver->resolve($options); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @return mixed|null |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getOption(string $name) |
|
38
|
|
|
{ |
|
39
|
|
|
if (isset($this->getOptions()[$name])) { |
|
40
|
|
|
return $this->getOptions()[$name]; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return null; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return mixed[] |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getOptions(): array |
|
50
|
|
|
{ |
|
51
|
|
|
if ($this->options === null) { |
|
52
|
|
|
$this->resolveOptions([]); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $this->options; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param mixed[] $options |
|
60
|
|
|
*/ |
|
61
|
|
|
public function setOptions(array $options): void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->options = $options; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getVisibilityLevel(): int |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->options[ConfigurationOptions::VISIBILITY_LEVELS]; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return string[] |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getAnnotationGroups(): array |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->options[ConfigurationOptions::ANNOTATION_GROUPS]; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getDestination(): string |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->options[ConfigurationOptions::DESTINATION]; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getTitle(): string |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->options[ConfigurationOptions::TITLE]; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getBaseUrl(): string |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->options[ConfigurationOptions::BASE_URL]; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getGoogleAnalytics(): string |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->options[ConfigurationOptions::GOOGLE_ANALYTICS]; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @return array|string[] |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getSource(): array |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->options[ConfigurationOptions::SOURCE]; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return array|string[] |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getExclude(): array |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->options[ConfigurationOptions::EXCLUDE]; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return string[] |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getExtensions(): array |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->options[ConfigurationOptions::EXTENSIONS]; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param mixed[] $options |
|
125
|
|
|
* @return mixed[] |
|
126
|
|
|
*/ |
|
127
|
|
|
private function unsetConsoleOptions(array $options): array |
|
128
|
|
|
{ |
|
129
|
|
|
unset( |
|
130
|
|
|
$options['ansi'], $options['no-ansi'], $options['no-interaction'], $options['config'], |
|
131
|
|
|
$options['help'], $options['quiet'], $options['verbose'], $options['version'] |
|
132
|
|
|
); |
|
133
|
|
|
return $options; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|