|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright © Vaimo Group. All rights reserved. |
|
4
|
|
|
* See LICENSE_VAIMO.txt for license details. |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Vaimo\ComposerChangelogs\Resolvers; |
|
7
|
|
|
|
|
8
|
|
|
use Composer\Package\PackageInterface; |
|
9
|
|
|
|
|
10
|
|
|
use Vaimo\ComposerChangelogs\Composer\Plugin\Config as PluginConfig; |
|
11
|
|
|
|
|
12
|
|
|
class ChangelogConfigResolver |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var \Composer\Package\PackageInterface |
|
16
|
|
|
*/ |
|
17
|
|
|
private $pluginPackage; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var \Vaimo\ComposerChangelogs\Composer\Plugin\Config |
|
21
|
|
|
*/ |
|
22
|
|
|
private $pluginConfig; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var \Vaimo\ComposerChangelogs\Interfaces\PackageConfigExtractorInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private $configExtractor; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var \Vaimo\ComposerChangelogs\Resolvers\PackageInfoResolver |
|
31
|
|
|
*/ |
|
32
|
|
|
private $packageInfoResolver; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var \Vaimo\ComposerChangelogs\Utils\DataUtils |
|
36
|
|
|
*/ |
|
37
|
|
|
private $dataUtils; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var \Vaimo\ComposerChangelogs\Utils\PathUtils |
|
41
|
|
|
*/ |
|
42
|
|
|
private $pathUtils; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param \Composer\Package\PackageInterface $pluginPackage |
|
46
|
|
|
* @param \Vaimo\ComposerChangelogs\Composer\Plugin\Config $pluginConfig |
|
47
|
|
|
* @param \Vaimo\ComposerChangelogs\Resolvers\PackageInfoResolver $packageInfoResolver |
|
48
|
|
|
* @param \Vaimo\ComposerChangelogs\Interfaces\PackageConfigExtractorInterface $configExtractor |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct( |
|
51
|
|
|
\Composer\Package\PackageInterface $pluginPackage, |
|
52
|
|
|
\Vaimo\ComposerChangelogs\Composer\Plugin\Config $pluginConfig, |
|
53
|
|
|
\Vaimo\ComposerChangelogs\Resolvers\PackageInfoResolver $packageInfoResolver, |
|
54
|
|
|
\Vaimo\ComposerChangelogs\Interfaces\PackageConfigExtractorInterface $configExtractor |
|
55
|
|
|
) { |
|
56
|
|
|
$this->pluginPackage = $pluginPackage; |
|
57
|
|
|
$this->pluginConfig = $pluginConfig; |
|
58
|
|
|
$this->packageInfoResolver = $packageInfoResolver; |
|
59
|
|
|
$this->configExtractor = $configExtractor; |
|
60
|
|
|
|
|
61
|
|
|
$this->dataUtils = new \Vaimo\ComposerChangelogs\Utils\DataUtils(); |
|
62
|
|
|
$this->pathUtils = new \Vaimo\ComposerChangelogs\Utils\PathUtils(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function resolveOutputTargets(PackageInterface $package) |
|
66
|
|
|
{ |
|
67
|
|
|
$config = $this->getConfig($package); |
|
68
|
|
|
|
|
69
|
|
|
if (!isset($config['output'])) { |
|
70
|
|
|
return array(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$installPath = $this->packageInfoResolver->getInstallPath($package); |
|
74
|
|
|
|
|
75
|
|
|
$dataUtils = $this->dataUtils; |
|
76
|
|
|
$pathUtils = $this->pathUtils; |
|
77
|
|
|
|
|
78
|
|
|
$allTargets = array_map(function ($config) use ($installPath, $dataUtils, $pathUtils) { |
|
79
|
|
|
$path = is_array($config) ? $dataUtils->extractValue($config, 'path') : $config; |
|
80
|
|
|
|
|
81
|
|
|
if (!$path) { |
|
82
|
|
|
return false; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return $pathUtils->composePath($installPath, $path); |
|
86
|
|
|
}, $config['output']); |
|
87
|
|
|
|
|
88
|
|
|
return array_filter($allTargets); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function resolveOutputEscapersForType($type) |
|
92
|
|
|
{ |
|
93
|
|
|
$escapers = $this->pluginConfig->getEscapers(); |
|
94
|
|
|
|
|
95
|
|
|
if (isset($escapers[$type])) { |
|
96
|
|
|
return $escapers[$type]; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return array(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function resolveRunnerInstallPath() |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->resolveInstallPath($this->pluginPackage); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function resolveInstallPath(PackageInterface $package) |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->packageInfoResolver->getInstallPath($package); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function resolveAvailableOutputFormats() |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->pluginConfig->getAvailableFormats(); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function resolveSourcePath(PackageInterface $package) |
|
118
|
|
|
{ |
|
119
|
|
|
$config = $this->getConfig($package); |
|
120
|
|
|
|
|
121
|
|
|
if (!isset($config['source'])) { |
|
122
|
|
|
return false; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
return $this->pathUtils->composePath( |
|
126
|
|
|
$this->packageInfoResolver->getInstallPath($package), |
|
127
|
|
|
$config['source'] |
|
128
|
|
|
); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function hasConfig(PackageInterface $package) |
|
132
|
|
|
{ |
|
133
|
|
|
$pkgExtraConfig = $this->configExtractor->getConfig($package); |
|
134
|
|
|
|
|
135
|
|
|
return isset($pkgExtraConfig[PluginConfig::ROOT]) |
|
136
|
|
|
&& is_array($pkgExtraConfig[PluginConfig::ROOT]); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function getFeatureFlags(PackageInterface $package) |
|
140
|
|
|
{ |
|
141
|
|
|
$config = $this->getConfig($package); |
|
142
|
|
|
|
|
143
|
|
|
return array_replace( |
|
144
|
|
|
array_fill_keys(array('links', 'dates'), true), |
|
145
|
|
|
isset($config['features']) ? $config['features'] : array() |
|
146
|
|
|
); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function getConfig(PackageInterface $package) |
|
150
|
|
|
{ |
|
151
|
|
|
$pkgExtraConfig = $this->configExtractor->getConfig($package); |
|
152
|
|
|
|
|
153
|
|
|
if (!isset($pkgExtraConfig[PluginConfig::ROOT]) || !is_array($pkgExtraConfig[PluginConfig::ROOT])) { |
|
154
|
|
|
return array(); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
return $pkgExtraConfig['changelog']; |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|