1 | <?php namespace Magestead\Helper; |
||
13 | class Options |
||
14 | { |
||
15 | const BOX_PREFIX = 'richdynamix/magestead-'; |
||
16 | |||
17 | protected $_app = 'magento2'; |
||
18 | protected $_phpVer = '56'; |
||
19 | protected $_os = 'centos65'; |
||
20 | protected $_server; |
||
21 | protected $_box; |
||
22 | protected $_m2Username; |
||
23 | protected $_m2Password; |
||
24 | protected $_ipAddress; |
||
25 | protected $_memorylimit; |
||
26 | protected $_cpus; |
||
27 | protected $_locale; |
||
28 | protected $_currency; |
||
29 | protected $_baseUrl; |
||
30 | protected $_repoUrl = ''; |
||
31 | |||
32 | /** |
||
33 | * Options constructor. |
||
34 | * @param $helper |
||
35 | * @param InputInterface $input |
||
36 | * @param OutputInterface $output |
||
37 | * @param $project |
||
38 | */ |
||
39 | public function __construct($helper, InputInterface $input, OutputInterface $output, $project) |
||
40 | { |
||
41 | $this->setVagrantSettings($helper, $input, $output); |
||
42 | |||
43 | $this->setServerConfig($helper, $input, $output); |
||
44 | |||
45 | $this->setApplicationSettings($helper, $input, $output, $project); |
||
46 | $this->setMagento2Settings($helper, $input, $output); |
||
47 | $this->setVersionControlSettings($helper, $input, $output); |
||
48 | |||
49 | $this->setVagrantBox(); |
||
50 | |||
51 | } |
||
52 | /** |
||
53 | * @return array |
||
54 | */ |
||
55 | public function getAllOptions() |
||
56 | { |
||
57 | return [ |
||
58 | 'app' => $this->_app, |
||
59 | 'server' => $this->_server, |
||
60 | 'phpver' => $this->_phpVer, |
||
61 | 'os' => $this->_os, |
||
62 | 'box' => $this->_box, |
||
63 | 'm2user' => $this->_m2Username, |
||
64 | 'm2pass' => $this->_m2Password, |
||
65 | 'repo_url' => $this->_repoUrl, |
||
66 | 'ip_address' => $this->_ipAddress, |
||
67 | 'cpus' => $this->_cpus, |
||
68 | 'memory_limit' => $this->_memorylimit, |
||
69 | 'locale' => $this->_locale, |
||
70 | 'default_currency' => $this->_currency, |
||
71 | 'base_url' => $this->_baseUrl, |
||
72 | ]; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param $helper |
||
77 | * @param InputInterface $input |
||
78 | * @param OutputInterface $output |
||
79 | */ |
||
80 | protected function setVagrantSettings($helper, InputInterface $input, OutputInterface $output) |
||
81 | { |
||
82 | $output->writeln('<comment>Lets configure your project\'s VM</comment>'); |
||
83 | |||
84 | $ipQuestion = new Question("Configure the IP for your VM (192.168.47.47): ", '192.168.47.47'); |
||
85 | $this->_ipAddress = strtolower($helper->ask($input, $output, $ipQuestion)); |
||
86 | |||
87 | $cpuQuestion = new Question("How many CPU's would you like to use? (1): ", '1'); |
||
88 | $this->_cpus = strtolower($helper->ask($input, $output, $cpuQuestion)); |
||
89 | |||
90 | $memoryQuestion = new Question("Define the VM memory limit (2048): ", '2048'); |
||
91 | $this->_memorylimit = strtolower($helper->ask($input, $output, $memoryQuestion)); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @param $helper |
||
96 | * @param InputInterface $input |
||
97 | * @param OutputInterface $output |
||
98 | * @param $project |
||
99 | */ |
||
100 | protected function setApplicationSettings($helper, InputInterface $input, OutputInterface $output, $project) |
||
101 | { |
||
102 | $output->writeln('<comment>Lets configure your project\'s application</comment>'); |
||
103 | $appQuestion = new ChoiceQuestion( |
||
104 | "Which application do you want to install?", |
||
105 | ['Magento', 'Magento2'], |
||
106 | 0 |
||
107 | ); |
||
108 | |||
109 | $this->_app = strtolower($helper->ask($input, $output, $appQuestion)); |
||
110 | |||
111 | $baseUrlQuestion = new Question("Enter your application's base_url ($project.dev): ", $project.'.dev'); |
||
112 | $this->_baseUrl = strtolower($helper->ask($input, $output, $baseUrlQuestion)); |
||
113 | |||
114 | $currenyQuestion = new Question("Enter your application's default currency (GBP): ", 'GBP'); |
||
115 | $this->_currency = $helper->ask($input, $output, $currenyQuestion); |
||
116 | |||
117 | $localeQuestion = new Question("Enter your application's default locale (en_GB): ", 'en_GB'); |
||
118 | $this->_locale = $helper->ask($input, $output, $localeQuestion); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * @param $helper |
||
123 | * @param InputInterface $input |
||
124 | * @param OutputInterface $output |
||
125 | * @return boolean|integer |
||
126 | */ |
||
127 | protected function setMagento2Settings($helper, InputInterface $input, OutputInterface $output) |
||
135 | |||
136 | /** |
||
137 | * @param $helper |
||
138 | * @param InputInterface $input |
||
139 | * @param OutputInterface $output |
||
140 | */ |
||
141 | protected function setVersionControlSettings($helper, InputInterface $input, OutputInterface $output) |
||
142 | { |
||
143 | $versionControl = new ConfirmationQuestion("Would you like to add your project to GIT? (no/yes) ", false); |
||
144 | $versioning = $helper->ask($input, $output, $versionControl); |
||
145 | if ($versioning) { |
||
146 | $repoQuestion = new Question("Enter your full GitHub/BitBucket repo URL: ", ''); |
||
147 | $this->_repoUrl = strtolower($helper->ask($input, $output, $repoQuestion)); |
||
148 | } |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @param $helper |
||
153 | * @param InputInterface $input |
||
154 | * @param OutputInterface $output |
||
155 | */ |
||
156 | protected function askForAuth($helper, InputInterface $input, OutputInterface $output) |
||
164 | |||
165 | /** |
||
166 | * @param $helper |
||
167 | * @param InputInterface $input |
||
168 | * @param OutputInterface $output |
||
169 | * @return boolean|integer |
||
170 | */ |
||
171 | protected function verifyAuth($helper, InputInterface $input, OutputInterface $output) |
||
193 | |||
194 | /** |
||
195 | * @param $helper |
||
196 | * @param InputInterface $input |
||
197 | * @param OutputInterface $output |
||
198 | */ |
||
199 | protected function setPhp($helper, InputInterface $input, OutputInterface $output) |
||
210 | |||
211 | /** |
||
212 | * Set box name from concat user options |
||
213 | */ |
||
214 | protected function setVagrantBox() |
||
218 | |||
219 | /** |
||
220 | * @param $helper |
||
221 | * @param InputInterface $input |
||
222 | * @param OutputInterface $output |
||
223 | */ |
||
224 | protected function setServerConfig($helper, InputInterface $input, OutputInterface $output) |
||
231 | |||
232 | /** |
||
233 | * @param $helper |
||
234 | * @param InputInterface $input |
||
235 | * @param OutputInterface $output |
||
236 | */ |
||
237 | protected function setWebServer($helper, InputInterface $input, OutputInterface $output) |
||
247 | |||
248 | /** |
||
249 | * @param $helper |
||
250 | * @param InputInterface $input |
||
251 | * @param OutputInterface $output |
||
252 | */ |
||
253 | protected function setOperatingSystem($helper, InputInterface $input, OutputInterface $output) |
||
263 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: