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
|
|
|
/** |
10
|
|
|
* Class Options |
11
|
|
|
* @package Magestead\Helper |
12
|
|
|
*/ |
13
|
|
|
class Options |
14
|
|
|
{ |
15
|
|
|
const BOX_PREFIX = 'richdynamix/magestead-'; |
16
|
|
|
protected $_app = 'magento2'; |
|
|
|
|
17
|
|
|
protected $_server; |
|
|
|
|
18
|
|
|
protected $_phpVer = '56'; |
|
|
|
|
19
|
|
|
protected $_os = 'centos65'; |
|
|
|
|
20
|
|
|
protected $_box; |
|
|
|
|
21
|
|
|
protected $_m2Username; |
|
|
|
|
22
|
|
|
protected $_m2Password; |
|
|
|
|
23
|
|
|
protected $_ipAddress; |
|
|
|
|
24
|
|
|
protected $_memorylimit; |
|
|
|
|
25
|
|
|
protected $_cpus; |
|
|
|
|
26
|
|
|
protected $_locale; |
|
|
|
|
27
|
|
|
protected $_currency; |
|
|
|
|
28
|
|
|
protected $_baseUrl; |
|
|
|
|
29
|
|
|
protected $_repoUrl = ''; |
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Options constructor. |
33
|
|
|
* @param $helper |
34
|
|
|
* @param InputInterface $input |
35
|
|
|
* @param OutputInterface $output |
36
|
|
|
*/ |
37
|
|
|
public function __construct($helper, InputInterface $input, OutputInterface $output) |
38
|
|
|
{ |
39
|
|
|
$this->setVagrantSettings($helper, $input, $output); |
40
|
|
|
|
41
|
|
|
$this->setServerConfig($helper, $input, $output); |
42
|
|
|
|
43
|
|
|
$this->setApplicationSettings($helper, $input, $output); |
44
|
|
|
$this->setMagento2Settings($helper, $input, $output); |
45
|
|
|
$this->setVersionControlSettings($helper, $input, $output); |
46
|
|
|
|
47
|
|
|
$this->setVagrantBox(); |
48
|
|
|
|
49
|
|
|
} |
50
|
|
|
/** |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
public function getAllOptions() |
54
|
|
|
{ |
55
|
|
|
return [ |
56
|
|
|
'app' => $this->_app, |
57
|
|
|
'server' => $this->_server, |
58
|
|
|
'phpver' => $this->_phpVer, |
59
|
|
|
'os' => $this->_os, |
60
|
|
|
'box' => $this->_box, |
61
|
|
|
'm2user' => $this->_m2Username, |
62
|
|
|
'm2pass' => $this->_m2Password, |
63
|
|
|
'repo_url' => $this->_repoUrl, |
64
|
|
|
'ip_address' => $this->_ipAddress, |
65
|
|
|
'cpus' => $this->_cpus, |
66
|
|
|
'memory_limit' => $this->_memorylimit, |
67
|
|
|
'locale' => $this->_locale, |
68
|
|
|
'default_currency' => $this->_currency, |
69
|
|
|
'base_url' => $this->_baseUrl, |
70
|
|
|
]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param $helper |
75
|
|
|
* @param InputInterface $input |
76
|
|
|
* @param OutputInterface $output |
77
|
|
|
*/ |
78
|
|
|
protected function setVagrantSettings($helper, InputInterface $input, OutputInterface $output) |
79
|
|
|
{ |
80
|
|
|
$output->writeln('<comment>Lets configure your project\'s VM</comment>'); |
81
|
|
|
|
82
|
|
|
$ipQuestion = new Question("Configure the IP for your VM (192.168.47.47): ", '192.168.47.47'); |
|
|
|
|
83
|
|
|
$this->_ipAddress = strtolower($helper->ask($input, $output, $ipQuestion)); |
84
|
|
|
|
85
|
|
|
$cpuQuestion = new Question("How many CPU's would you like to use? (1): ", '1'); |
86
|
|
|
$this->_cpus = strtolower($helper->ask($input, $output, $cpuQuestion)); |
87
|
|
|
|
88
|
|
|
$memoryQuestion = new Question("Define the VM memory limit (2048): ", '2048'); |
|
|
|
|
89
|
|
|
$this->_memorylimit = strtolower($helper->ask($input, $output, $memoryQuestion)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param $helper |
94
|
|
|
* @param InputInterface $input |
95
|
|
|
* @param OutputInterface $output |
96
|
|
|
*/ |
97
|
|
|
protected function setApplicationSettings($helper, InputInterface $input, OutputInterface $output) |
98
|
|
|
{ |
99
|
|
|
$output->writeln('<comment>Lets configure your project\'s application</comment>'); |
100
|
|
|
if ($this->_phpVer !== '70') { |
101
|
|
|
$appQuestion = new ChoiceQuestion( |
102
|
|
|
"Which application do you want to install?", |
|
|
|
|
103
|
|
|
['Magento', 'Magento 2'], |
104
|
|
|
0 |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$this->_app = strtolower($helper->ask($input, $output, $appQuestion)); |
108
|
|
|
} |
109
|
|
|
$baseUrlQuestion = new Question("Enter your application's base_url (magestead.dev): ", 'magestead.dev'); |
110
|
|
|
$this->_baseUrl = strtolower($helper->ask($input, $output, $baseUrlQuestion)); |
|
|
|
|
111
|
|
|
|
112
|
|
|
$currenyQuestion = new Question("Enter your application's default currency (GBP): ", 'GBP'); |
113
|
|
|
$this->_currency = $helper->ask($input, $output, $currenyQuestion); |
114
|
|
|
|
115
|
|
|
$localeQuestion = new Question("Enter your application's default locale (en_GB): ", 'en_GB'); |
116
|
|
|
$this->_locale = $helper->ask($input, $output, $localeQuestion); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param $helper |
121
|
|
|
* @param InputInterface $input |
122
|
|
|
* @param OutputInterface $output |
123
|
|
|
* @return bool |
|
|
|
|
124
|
|
|
*/ |
125
|
|
|
protected function setMagento2Settings($helper, InputInterface $input, OutputInterface $output) |
126
|
|
|
{ |
127
|
|
|
if ($this->_app === 'magento2') { |
128
|
|
|
return $this->verifyAuth($helper, $input, $output); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return true; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param $helper |
136
|
|
|
* @param InputInterface $input |
137
|
|
|
* @param OutputInterface $output |
138
|
|
|
*/ |
139
|
|
|
protected function setVersionControlSettings($helper, InputInterface $input, OutputInterface $output) |
140
|
|
|
{ |
141
|
|
|
$versionControl = new ConfirmationQuestion("Would you like to add your project to GIT? (no/yes) ", false); |
|
|
|
|
142
|
|
|
$versioning = $helper->ask($input, $output, $versionControl); |
|
|
|
|
143
|
|
|
if ($versioning) { |
144
|
|
|
$repoQuestion = new Question("Enter your full GitHub/BitBucket repo URL: ", ''); |
|
|
|
|
145
|
|
|
$this->_repoUrl = strtolower($helper->ask($input, $output, $repoQuestion)); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param $helper |
151
|
|
|
* @param InputInterface $input |
152
|
|
|
* @param OutputInterface $output |
153
|
|
|
*/ |
154
|
|
|
protected function askForAuth($helper, InputInterface $input, OutputInterface $output) |
155
|
|
|
{ |
156
|
|
|
$username = new Question("Please enter your Magento username (public key): ", ''); |
|
|
|
|
157
|
|
|
$this->_m2Username = $helper->ask($input, $output, $username); |
158
|
|
|
|
159
|
|
|
$password = new Question("Please enter your Magento password (private key): ", ''); |
|
|
|
|
160
|
|
|
$this->_m2Password = $helper->ask($input, $output, $password); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param $helper |
165
|
|
|
* @param InputInterface $input |
166
|
|
|
* @param OutputInterface $output |
167
|
|
|
* @return bool |
|
|
|
|
168
|
|
|
*/ |
169
|
|
|
protected function verifyAuth($helper, InputInterface $input, OutputInterface $output) |
|
|
|
|
170
|
|
|
{ |
171
|
|
|
$authFile = $_SERVER['HOME'] . "/.composer/auth.json"; |
|
|
|
|
172
|
|
|
|
173
|
|
|
$authObj = []; |
174
|
|
|
if (file_exists($authFile)) { |
175
|
|
|
$authJson = file_get_contents($authFile); |
176
|
|
|
$authObj = (array)json_decode($authJson); |
|
|
|
|
177
|
|
|
|
178
|
|
|
if (isset($authObj['http-basic']) && isset($authObj['http-basic']->{'repo.magento.com'})) { |
179
|
|
|
return true; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
$this->askForAuth($helper, $input, $output); |
184
|
|
|
|
185
|
|
|
$authObj['http-basic']['repo.magento.com']['username'] = $this->_m2Username; |
186
|
|
|
$authObj['http-basic']['repo.magento.com']['password'] = $this->_m2Password; |
187
|
|
|
|
188
|
|
|
$authJson = json_encode($authObj); |
189
|
|
|
return file_put_contents($authFile, $authJson); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param $helper |
194
|
|
|
* @param InputInterface $input |
195
|
|
|
* @param OutputInterface $output |
196
|
|
|
*/ |
197
|
|
|
protected function setPhp($helper, InputInterface $input, OutputInterface $output) |
198
|
|
|
{ |
199
|
|
|
$output->writeln('<info>Keep in mind PHP7 is only available for Magento 2</info>'); |
200
|
|
|
$phpVerQuestion = new ChoiceQuestion( |
201
|
|
|
"Which version of PHP should be installed?", |
|
|
|
|
202
|
|
|
['56', '70'], |
203
|
|
|
0 |
204
|
|
|
); |
205
|
|
|
|
206
|
|
|
$this->_phpVer = $helper->ask($input, $output, $phpVerQuestion); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Set box name from concat user options |
211
|
|
|
*/ |
212
|
|
|
protected function setVagrantBox() |
213
|
|
|
{ |
214
|
|
|
$this->_box = self::BOX_PREFIX . $this->_os . "-$this->_server-php$this->_phpVer"; |
|
|
|
|
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param $helper |
219
|
|
|
* @param InputInterface $input |
220
|
|
|
* @param OutputInterface $output |
221
|
|
|
*/ |
222
|
|
|
protected function setServerConfig($helper, InputInterface $input, OutputInterface $output) |
223
|
|
|
{ |
224
|
|
|
$output->writeln('<comment>Lets configure your server</comment>'); |
225
|
|
|
$this->setOperatingSystem($helper, $input, $output); |
226
|
|
|
$this->setWebServer($helper, $input, $output); |
227
|
|
|
$this->setPhp($helper, $input, $output); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param $helper |
232
|
|
|
* @param InputInterface $input |
233
|
|
|
* @param OutputInterface $output |
234
|
|
|
*/ |
235
|
|
|
protected function setWebServer($helper, InputInterface $input, OutputInterface $output) |
236
|
|
|
{ |
237
|
|
|
$serverQuestion = new ChoiceQuestion( |
238
|
|
|
"Which webserver would you like?", |
|
|
|
|
239
|
|
|
['NGINX', 'Apache'], |
240
|
|
|
0 |
241
|
|
|
); |
242
|
|
|
$this->_server = strtolower($helper->ask($input, $output, $serverQuestion)); |
|
|
|
|
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param $helper |
247
|
|
|
* @param InputInterface $input |
248
|
|
|
* @param OutputInterface $output |
249
|
|
|
*/ |
250
|
|
|
protected function setOperatingSystem($helper, InputInterface $input, OutputInterface $output) |
251
|
|
|
{ |
252
|
|
|
$osQuestion = new ChoiceQuestion( |
253
|
|
|
"Which OS would you like to install?", |
|
|
|
|
254
|
|
|
['CentOS 6.5', 'Ubuntu 14'], |
255
|
|
|
0 |
256
|
|
|
); |
257
|
|
|
$this->_os = str_replace(' ', '', str_replace('.', '', strtolower($helper->ask($input, $output, $osQuestion)))); |
|
|
|
|
258
|
|
|
} |
259
|
|
|
} |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.