|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Module\Configuration\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Composer\IO\IOInterface; |
|
6
|
|
|
use PhpGitHooks\Module\Configuration\Domain\CommitMsg; |
|
7
|
|
|
use PhpGitHooks\Module\Configuration\Domain\Config; |
|
8
|
|
|
use PhpGitHooks\Module\Configuration\Domain\PreCommit; |
|
9
|
|
|
use PhpGitHooks\Module\Configuration\Domain\PrePush; |
|
10
|
|
|
use PhpGitHooks\Module\Configuration\Infrastructure\Hook\HookCopier; |
|
11
|
|
|
use PhpGitHooks\Module\Configuration\Model\ConfigurationFileReaderInterface; |
|
12
|
|
|
use PhpGitHooks\Module\Configuration\Model\ConfigurationFileWriterInterface; |
|
13
|
|
|
|
|
14
|
|
|
class ConfigurationProcessor |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var IOInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $io; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var PreCommitProcessor |
|
22
|
|
|
*/ |
|
23
|
|
|
private $preCommitProcessor; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var CommitMsgProcessor |
|
26
|
|
|
*/ |
|
27
|
|
|
private $commitMsgProcessor; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var ConfigurationFileWriterInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $configurationFileWriter; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var HookCopier |
|
34
|
|
|
*/ |
|
35
|
|
|
private $hookCopier; |
|
36
|
|
|
/** |
|
37
|
|
|
* @var ConfigurationFileReaderInterface |
|
38
|
|
|
*/ |
|
39
|
|
|
private $configurationFileReader; |
|
40
|
|
|
/** |
|
41
|
|
|
* @var PrePushProcessor |
|
42
|
|
|
*/ |
|
43
|
|
|
private $prePushProcessor; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* ConfigurationProcessor constructor. |
|
47
|
|
|
* |
|
48
|
|
|
* @param ConfigurationFileReaderInterface $configurationFileReader |
|
49
|
|
|
* @param PreCommitProcessor $preCommitProcessor |
|
50
|
|
|
* @param CommitMsgProcessor $commitMsgProcessor |
|
51
|
|
|
* @param ConfigurationFileWriterInterface $configurationFileWriter |
|
52
|
|
|
* @param HookCopier $hookCopier |
|
53
|
|
|
* @param PrePushProcessor $prePushProcessor |
|
54
|
|
|
*/ |
|
55
|
2 |
|
public function __construct( |
|
56
|
|
|
ConfigurationFileReaderInterface $configurationFileReader, |
|
57
|
|
|
PreCommitProcessor $preCommitProcessor, |
|
58
|
|
|
CommitMsgProcessor $commitMsgProcessor, |
|
59
|
|
|
ConfigurationFileWriterInterface $configurationFileWriter, |
|
60
|
|
|
HookCopier $hookCopier, |
|
61
|
|
|
PrePushProcessor $prePushProcessor |
|
62
|
|
|
) { |
|
63
|
2 |
|
$this->preCommitProcessor = $preCommitProcessor; |
|
64
|
2 |
|
$this->commitMsgProcessor = $commitMsgProcessor; |
|
65
|
2 |
|
$this->configurationFileWriter = $configurationFileWriter; |
|
66
|
2 |
|
$this->hookCopier = $hookCopier; |
|
67
|
2 |
|
$this->configurationFileReader = $configurationFileReader; |
|
68
|
2 |
|
$this->prePushProcessor = $prePushProcessor; |
|
69
|
2 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param IOInterface $input |
|
73
|
|
|
*/ |
|
74
|
2 |
|
public function process(IOInterface $input) |
|
75
|
|
|
{ |
|
76
|
2 |
|
$this->io = $input; |
|
77
|
|
|
|
|
78
|
2 |
|
$configData = $this->configurationFileReader->getData(); |
|
79
|
2 |
|
$preCommit = $this->preCommitProcess($configData); |
|
80
|
|
|
|
|
81
|
2 |
|
if (true === $preCommit->isEnabled()) { |
|
82
|
2 |
|
$this->hookCopier->copyPreCommitHook(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
2 |
|
$commitMsg = $this->commitMsgProcess($configData); |
|
86
|
|
|
|
|
87
|
2 |
|
if (true === $commitMsg->isEnabled()) { |
|
88
|
2 |
|
$this->hookCopier->copyCommitMsgHook(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
2 |
|
$prePush = $this->prePushProcess($configData); |
|
92
|
|
|
|
|
93
|
2 |
|
if (true === $prePush->isEnabled()) { |
|
94
|
2 |
|
$this->hookCopier->copyPrePushHook(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
2 |
|
$configArray = ConfigurationArrayTransformer::transform($preCommit, $commitMsg, $prePush); |
|
98
|
|
|
|
|
99
|
2 |
|
$this->configurationFileWriter->write($configArray); |
|
100
|
2 |
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param Config $configData |
|
104
|
|
|
* |
|
105
|
|
|
* @return PreCommit |
|
106
|
|
|
*/ |
|
107
|
2 |
|
private function preCommitProcess(Config $configData) |
|
108
|
|
|
{ |
|
109
|
|
|
/** @var PreCommit $preCommitData */ |
|
110
|
2 |
|
$preCommitData = $configData->getPreCommit(); |
|
111
|
|
|
|
|
112
|
2 |
|
return $this->preCommitProcessor->process($preCommitData, $this->io); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param Config $configData |
|
117
|
|
|
* |
|
118
|
|
|
* @return CommitMsg |
|
119
|
|
|
*/ |
|
120
|
2 |
|
private function commitMsgProcess(Config $configData) |
|
121
|
|
|
{ |
|
122
|
|
|
/** @var CommitMsg $commitMsgData */ |
|
123
|
2 |
|
$commitMsgData = $configData->getCommitMsg(); |
|
124
|
|
|
|
|
125
|
2 |
|
return $this->commitMsgProcessor->process($commitMsgData, $this->io); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param Config $configData |
|
130
|
|
|
* |
|
131
|
|
|
* @return PrePush |
|
132
|
|
|
*/ |
|
133
|
2 |
|
private function prePushProcess(Config $configData) |
|
134
|
|
|
{ |
|
135
|
|
|
/** @var PrePush $prePush */ |
|
136
|
2 |
|
$prePush = $configData->getPrePush(); |
|
137
|
|
|
|
|
138
|
2 |
|
return $this->prePushProcessor->process($prePush, $this->io); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|