|
1
|
|
|
<?php namespace Magestead\Helper; |
|
2
|
|
|
|
|
3
|
|
|
use Symfony\Component\Console\Question\Question; |
|
4
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
5
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
6
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
|
7
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
|
8
|
|
|
|
|
9
|
|
|
class Options |
|
10
|
|
|
{ |
|
11
|
|
|
protected $_app; |
|
12
|
|
|
protected $_server; |
|
13
|
|
|
protected $_phpVer = '56'; |
|
14
|
|
|
protected $_box; |
|
15
|
|
|
protected $_m2Username; |
|
16
|
|
|
protected $_m2Password; |
|
17
|
|
|
protected $_ipAddress; |
|
18
|
|
|
protected $_cpus; |
|
19
|
|
|
protected $_locale; |
|
20
|
|
|
protected $_currency; |
|
21
|
|
|
protected $_baseUrl; |
|
22
|
|
|
protected $_repoUrl = ''; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Options constructor. |
|
26
|
|
|
* @param $helper |
|
27
|
|
|
* @param InputInterface $input |
|
28
|
|
|
* @param OutputInterface $output |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct($helper, InputInterface $input, OutputInterface $output) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->getVagrantSettings($helper, $input, $output); |
|
33
|
|
|
$this->getApplicationSettings($helper, $input, $output); |
|
34
|
|
|
$this->getMagento2Settings($helper, $input, $output); |
|
35
|
|
|
$this->getVersionControlSettings($helper, $input, $output); |
|
36
|
|
|
|
|
37
|
|
|
$this->_box = "centos65+$this->_server+php$this->_phpVer"; |
|
38
|
|
|
} |
|
39
|
|
|
/** |
|
40
|
|
|
* @return array |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getAllOptions() |
|
43
|
|
|
{ |
|
44
|
|
|
return [ |
|
45
|
|
|
'app' => $this->getApp(), |
|
46
|
|
|
'server' => $this->getServer(), |
|
47
|
|
|
'phpver' => $this->getPhpVer(), |
|
48
|
|
|
'box' => $this->getBox(), |
|
49
|
|
|
'm2user' => $this->getM2Username(), |
|
50
|
|
|
'm2pass' => $this->getM2Password(), |
|
51
|
|
|
'repo_url' => $this->getRepoUrl(), |
|
52
|
|
|
'ip_address' => $this->getIpAddress(), |
|
53
|
|
|
'cpus' => $this->getCpus(), |
|
54
|
|
|
'memory_limit' => $this->getMemorylimit(), |
|
55
|
|
|
'locale' => $this->getLocale(), |
|
56
|
|
|
'default_currency' => $this->getCurrency(), |
|
57
|
|
|
'base_url' => $this->getBaseUrl(), |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return mixed |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getApp() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->_app; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return mixed |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getServer() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->_server; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getPhpVer() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->_phpVer; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return mixed |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getBox() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->_box; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return mixed |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getM2Username() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->_m2Username; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return mixed |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getM2Password() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->_m2Password; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return string |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getMemorylimit() |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->_memorylimit; |
|
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return string |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getIpAddress() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->_ipAddress; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @return mixed |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getCpus() |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->_cpus; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return string |
|
135
|
|
|
*/ |
|
136
|
|
|
public function getRepoUrl() |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->_repoUrl; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return mixed |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getLocale() |
|
145
|
|
|
{ |
|
146
|
|
|
return $this->_locale; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return mixed |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getCurrency() |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->_currency; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return mixed |
|
159
|
|
|
*/ |
|
160
|
|
|
public function getBaseUrl() |
|
161
|
|
|
{ |
|
162
|
|
|
return $this->_baseUrl; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @param $helper |
|
167
|
|
|
* @param InputInterface $input |
|
168
|
|
|
* @param OutputInterface $output |
|
169
|
|
|
*/ |
|
170
|
|
|
protected function getVagrantSettings($helper, InputInterface $input, OutputInterface $output) |
|
171
|
|
|
{ |
|
172
|
|
|
$output->writeln('<comment>Lets configure your project\'s VM</comment>'); |
|
173
|
|
|
|
|
174
|
|
|
$ipQuestion = new Question("Configure the IP for your VM (192.168.47.47): ", '192.168.47.47'); |
|
175
|
|
|
$this->_ipAddress = strtolower($helper->ask($input, $output, $ipQuestion)); |
|
176
|
|
|
|
|
177
|
|
|
$cpuQuestion = new Question("How many CPU's would you like to use? (1): ", '1'); |
|
178
|
|
|
$this->_cpus = strtolower($helper->ask($input, $output, $cpuQuestion)); |
|
179
|
|
|
|
|
180
|
|
|
$memoryQuestion = new Question("Define the VM memory limit (2048): ", '2048'); |
|
181
|
|
|
$this->_memorylimit = strtolower($helper->ask($input, $output, $memoryQuestion)); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @param $helper |
|
186
|
|
|
* @param InputInterface $input |
|
187
|
|
|
* @param OutputInterface $output |
|
188
|
|
|
*/ |
|
189
|
|
|
protected function getApplicationSettings($helper, InputInterface $input, OutputInterface $output) |
|
190
|
|
|
{ |
|
191
|
|
|
$output->writeln('<comment>Lets configure your project\'s application</comment>'); |
|
192
|
|
|
$appQuestion = new ChoiceQuestion( |
|
193
|
|
|
"Which application do you want to install?", |
|
194
|
|
|
['Magento', 'Magento 2'], |
|
195
|
|
|
0 |
|
196
|
|
|
); |
|
197
|
|
|
$this->_app = strtolower($helper->ask($input, $output, $appQuestion)); |
|
198
|
|
|
|
|
199
|
|
|
$baseUrlQuestion = new Question("Enter your application's base_url (magestead.dev): ", 'magestead.dev'); |
|
200
|
|
|
$this->_baseUrl = strtolower($helper->ask($input, $output, $baseUrlQuestion)); |
|
201
|
|
|
|
|
202
|
|
|
$currenyQuestion = new Question("Enter your application's default currency (GBP): ", 'GBP'); |
|
203
|
|
|
$this->_currency = $helper->ask($input, $output, $currenyQuestion); |
|
204
|
|
|
|
|
205
|
|
|
$localeQuestion = new Question("Enter your application's default locale (en_GB): ", 'en_GB'); |
|
206
|
|
|
$this->_locale = $helper->ask($input, $output, $localeQuestion); |
|
207
|
|
|
|
|
208
|
|
|
$serverQuestion = new ChoiceQuestion( |
|
209
|
|
|
"Which webserver would you like?", |
|
210
|
|
|
['NGINX', 'Apache'], |
|
211
|
|
|
0 |
|
212
|
|
|
); |
|
213
|
|
|
$this->_server = strtolower($helper->ask($input, $output, $serverQuestion)); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @param $helper |
|
218
|
|
|
* @param InputInterface $input |
|
219
|
|
|
* @param OutputInterface $output |
|
220
|
|
|
* @return bool |
|
221
|
|
|
*/ |
|
222
|
|
|
protected function getMagento2Settings($helper, InputInterface $input, OutputInterface $output) |
|
223
|
|
|
{ |
|
224
|
|
|
// todo add php 7 enabled box |
|
225
|
|
|
// $this->usePhp7($helper, $input, $output); |
|
|
|
|
|
|
226
|
|
|
|
|
227
|
|
|
if ($this->_app === 'magento 2') { |
|
228
|
|
|
return $this->verifyAuth($helper, $input, $output); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
return true; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* @param $helper |
|
236
|
|
|
* @param InputInterface $input |
|
237
|
|
|
* @param OutputInterface $output |
|
238
|
|
|
*/ |
|
239
|
|
|
protected function getVersionControlSettings($helper, InputInterface $input, OutputInterface $output) |
|
240
|
|
|
{ |
|
241
|
|
|
$versionControl = new ConfirmationQuestion("Would you like to add your project to GIT? (yes/no) ", true); |
|
242
|
|
|
$versioning = $helper->ask($input, $output, $versionControl); |
|
243
|
|
|
if ($versioning) { |
|
244
|
|
|
$repoQuestion = new Question("Enter your full GitHub/BitBucket repo URL: ", ''); |
|
245
|
|
|
$this->_repoUrl = strtolower($helper->ask($input, $output, $repoQuestion)); |
|
246
|
|
|
} |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* @param $helper |
|
251
|
|
|
* @param InputInterface $input |
|
252
|
|
|
* @param OutputInterface $output |
|
253
|
|
|
*/ |
|
254
|
|
|
protected function askForAuth($helper, InputInterface $input, OutputInterface $output) |
|
255
|
|
|
{ |
|
256
|
|
|
$username = new Question("Please enter your Magento username (public key): ", ''); |
|
257
|
|
|
$this->_m2Username = $helper->ask($input, $output, $username); |
|
258
|
|
|
|
|
259
|
|
|
$password = new Question("Please enter your Magento password (private key): ", ''); |
|
260
|
|
|
$this->_m2Password = $helper->ask($input, $output, $password); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* @param $helper |
|
265
|
|
|
* @param InputInterface $input |
|
266
|
|
|
* @param OutputInterface $output |
|
267
|
|
|
* @return bool |
|
268
|
|
|
*/ |
|
269
|
|
|
protected function verifyAuth($helper, InputInterface $input, OutputInterface $output) |
|
|
|
|
|
|
270
|
|
|
{ |
|
271
|
|
|
$authFile = $_SERVER['HOME'] . "/.composer/auth.json"; |
|
272
|
|
|
|
|
273
|
|
|
$authJson = file_get_contents($authFile); |
|
274
|
|
|
$authObj = (array)json_decode($authJson); |
|
275
|
|
|
|
|
276
|
|
|
if (isset($authObj['http-basic']) && isset($authObj['http-basic']->{'repo.magento.com'})) { |
|
277
|
|
|
return true; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
$this->askForAuth($helper, $input, $output); |
|
281
|
|
|
|
|
282
|
|
|
$authObj['http-basic']['repo.magento.com']['username'] = $this->_m2Username; |
|
283
|
|
|
$authObj['http-basic']['repo.magento.com']['password'] = $this->_m2Password; |
|
284
|
|
|
|
|
285
|
|
|
$authJson = json_encode($authObj); |
|
286
|
|
|
return file_put_contents($authFile, $authJson); |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* @param $helper |
|
291
|
|
|
* @param InputInterface $input |
|
292
|
|
|
* @param OutputInterface $output |
|
293
|
|
|
*/ |
|
294
|
|
|
protected function usePhp7($helper, InputInterface $input, OutputInterface $output) |
|
295
|
|
|
{ |
|
296
|
|
|
if ($this->_app !== 'magento' && $this->_server !== 'apache') { |
|
297
|
|
|
$phpVerQuestion = new ChoiceQuestion( |
|
298
|
|
|
"Which version of PHP should be installed?", |
|
299
|
|
|
['56', '7'], |
|
300
|
|
|
0 |
|
301
|
|
|
); |
|
302
|
|
|
$this->_phpVer = $helper->ask($input, $output, $phpVerQuestion); |
|
303
|
|
|
} |
|
304
|
|
|
} |
|
305
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: