1 | <?php |
||
8 | class HostnameFromComposerResolver implements HostnameResolver |
||
9 | { |
||
10 | /** |
||
11 | * {@inheritdoc} |
||
12 | */ |
||
13 | public function getExtraHostnameConfigurations(Project $project) |
||
14 | { |
||
15 | $composerFile = $this->getComposerJsonFilePath($project); |
||
16 | if (!file_exists($composerFile)) { |
||
17 | return []; |
||
18 | } |
||
19 | |||
20 | $contents = json_decode(file_get_contents($composerFile), true); |
||
21 | $accessor = PropertyAccess::createPropertyAccessor(); |
||
22 | $componentsConfiguration = $accessor->getValue($contents, '[extra][dock-cli][extra-hostname]'); |
||
23 | if (!is_array($componentsConfiguration)) { |
||
24 | return []; |
||
25 | } |
||
26 | |||
27 | $configurations = []; |
||
28 | foreach ($componentsConfiguration as $componentName => $hostNames) { |
||
29 | if (!is_array($hostNames)) { |
||
30 | $hostNames = [$hostNames]; |
||
31 | } |
||
32 | |||
33 | foreach ($hostNames as $hostname) { |
||
34 | $configurations[] = new HostnameConfiguration($componentName, $hostname); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | return $configurations; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @param Project $project |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | private function getComposerJsonFilePath(Project $project) |
||
50 | } |
||
51 |