1 | <?php |
||
8 | class Config { |
||
9 | |||
10 | private $config; |
||
11 | |||
12 | 6 | public function __construct($profile = null) { |
|
13 | 6 | $profileDir = __DIR__ . '/../../profiles'; |
|
14 | |||
15 | 6 | $locator = new FileLocator([$profileDir]); |
|
16 | 6 | $loader = new YamlLoader($locator); |
|
17 | 6 | $builtIns = $this->readProfiles($loader, $profileDir); |
|
18 | |||
19 | 6 | $profiles = []; |
|
20 | 6 | $isBuiltin = in_array($profile, $builtIns); |
|
21 | |||
22 | 6 | if ($isBuiltin) { |
|
23 | $profiles[] = $loader->load($locator->locate($profile . '.yml', null, true)); |
||
24 | } else { |
||
25 | 6 | $profiles[] = $loader->load($locator->locate('default.yml', null, true)); |
|
26 | } |
||
27 | |||
28 | 6 | if (!empty($profile) && !$isBuiltin && file_exists($profile)) { |
|
29 | $profiles[] = $loader->load(file_get_contents($profile)); |
||
30 | } |
||
31 | |||
32 | 6 | $processor = new Processor(); |
|
33 | 6 | $definition = new ProfileDefinition(); |
|
34 | 6 | $this->config = $processor->processConfiguration($definition, $profiles); |
|
35 | 6 | } |
|
36 | |||
37 | 6 | private function readProfiles(YamlLoader $loader, $profileDir) { |
|
38 | 6 | $profiles = []; |
|
39 | 6 | foreach (new \DirectoryIterator($profileDir) as $file) { |
|
40 | 6 | if ($file->isFile() && $loader->supports($file->getFilename())) { |
|
41 | 6 | $profiles[] = $file->getFilename(); |
|
42 | 6 | } |
|
43 | 6 | } |
|
44 | |||
45 | 6 | return $profiles; |
|
46 | } |
||
47 | |||
48 | 1 | public function getConfig() { |
|
49 | 1 | return $this->config; |
|
50 | } |
||
51 | |||
52 | 3 | public function getIndentation($key) { |
|
|
|||
53 | 3 | if (isset($this->config['indentation'][$key])) { |
|
54 | 3 | return $this->config['indentation'][$key]; |
|
55 | } |
||
56 | } |
||
57 | |||
58 | 3 | public function getBraces($key) { |
|
59 | 3 | if (isset($this->config['braces'][$key])) { |
|
60 | 3 | return $this->config['braces'][$key]; |
|
61 | } |
||
62 | } |
||
63 | |||
64 | 3 | public function getWhitespace($key, $context = 'default') { |
|
65 | 3 | if (isset($this->config['whitespace'][$context][$key])) { |
|
66 | 3 | $val = $this->config['whitespace'][$context][$key]; |
|
67 | |||
68 | 3 | if ($val === 'default' && $context !== 'default') { |
|
69 | return $this->getWhitespace($key); |
||
70 | } |
||
71 | 3 | return $val; |
|
72 | 2 | } else if ($context !== 'default') { // workaround? |
|
73 | 2 | return $this->getWhitespace($key); |
|
74 | } |
||
75 | return false; |
||
76 | } |
||
77 | |||
78 | 1 | public function getBlanks($key) { |
|
79 | 1 | if (isset($this->config['blanks'][$key])) { |
|
80 | 1 | return $this->config['blanks'][$key]; |
|
81 | } |
||
82 | 1 | return 0; |
|
83 | } |
||
84 | |||
85 | 1 | public function getNewline($key) { |
|
90 | } |
||
91 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.