|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of EC-CUBE |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
|
7
|
|
|
* |
|
8
|
|
|
* http://www.lockon.co.jp/ |
|
9
|
|
|
* |
|
10
|
|
|
* This program is free software; you can redistribute it and/or |
|
11
|
|
|
* modify it under the terms of the GNU General Public License |
|
12
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
13
|
|
|
* of the License, or (at your option) any later version. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU General Public License |
|
21
|
|
|
* along with this program; if not, write to the Free Software |
|
22
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace Eccube\Command\PluginCommand; |
|
26
|
|
|
|
|
27
|
|
|
use Eccube\Common\Constant; |
|
28
|
|
|
use Symfony\Component\Console\Question\Question; |
|
29
|
|
|
|
|
30
|
|
|
abstract class AbstractPluginGenerator |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
|
|
33
|
|
|
const DEFAULT_NESTING_LEVEL = 100; |
|
34
|
|
|
const NEW_HOOK_VERSION = '3.0.9'; |
|
35
|
|
|
const STOP_PROCESS = 'quit'; |
|
36
|
|
|
const INPUT_OPEN = '['; |
|
37
|
|
|
const INPUT_CLOSE = ']'; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* app |
|
41
|
|
|
* @var \Eccube\Application |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $app; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* QuestionHelper |
|
47
|
|
|
* @var \Symfony\Component\Console\Helper\QuestionHelper |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $dialog; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* InputInterface |
|
53
|
|
|
* @var \Symfony\Component\Console\Input\InputInterface |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $input; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* InputInterface |
|
59
|
|
|
* @var \Symfony\Component\Console\Output\OutputInterface |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $output; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* $paramList |
|
65
|
|
|
* @var array $paramList |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $paramList; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* |
|
71
|
|
|
* @var int |
|
72
|
|
|
*/ |
|
73
|
|
|
private $nestingLevel; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* ヘッダー |
|
77
|
|
|
*/ |
|
78
|
|
|
abstract protected function getHeader(); |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* start() |
|
82
|
|
|
*/ |
|
83
|
|
|
abstract protected function start(); |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* フィルドーセット |
|
87
|
|
|
*/ |
|
88
|
|
|
abstract protected function initFildset(); |
|
89
|
|
|
|
|
90
|
|
|
public function __construct(\Eccube\Application $app) |
|
|
|
|
|
|
91
|
|
|
{ |
|
92
|
|
|
$this->app = $app; |
|
93
|
|
|
$this->nestingLevel = self::DEFAULT_NESTING_LEVEL; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* |
|
98
|
|
|
* @param \Symfony\Component\Console\Helper\QuestionHelper $dialog |
|
|
|
|
|
|
99
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
|
|
|
|
|
100
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
101
|
|
|
*/ |
|
102
|
|
|
public function init($dialog, $input, $output) |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
|
|
$this->dialog = $dialog; |
|
105
|
|
|
$this->input = $input; |
|
106
|
|
|
$this->output = $output; |
|
107
|
|
|
$this->initFildset(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function run() |
|
|
|
|
|
|
111
|
|
|
{ |
|
112
|
|
|
//ヘッダー部分 |
|
113
|
|
|
$this->getHeader(); |
|
114
|
|
|
|
|
115
|
|
|
foreach ($this->paramList as $paramKey => $params) { |
|
116
|
|
|
$value = $this->makeLineRequest($params); |
|
117
|
|
|
if ($value === false) { |
|
118
|
|
|
$this->exitGenerator(); |
|
119
|
|
|
return; |
|
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
$this->paramList[$paramKey]['value'] = $value; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
$this->output->writeln(''); |
|
125
|
|
|
$this->output->writeln('---Entry confirmation'); |
|
126
|
|
|
foreach ($this->paramList as $paramKey => $params) { |
|
127
|
|
|
if (is_array($params['value'])) { |
|
128
|
|
|
$this->output->writeln($params['label']); |
|
129
|
|
|
foreach ($params['value'] as $keys => $val) { |
|
130
|
|
|
$this->output->writeln('<info> ' . $keys . '</info>'); |
|
|
|
|
|
|
131
|
|
|
} |
|
132
|
|
|
} else { |
|
133
|
|
|
if (isset($params['show'])) { |
|
134
|
|
|
$disp = $params['show'][$params['value']]; |
|
135
|
|
|
} else { |
|
136
|
|
|
$disp = $params['value']; |
|
137
|
|
|
} |
|
138
|
|
|
$this->output->writeln($params['label'] . ' <info>' . $disp . '</info>'); |
|
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
$this->output->writeln(''); |
|
142
|
|
|
$Question = new Question('<comment>[confirm] Do you want to proceed? [y/n] : </comment>', ''); |
|
143
|
|
|
$value = $this->dialog->ask($this->input, $this->output, $Question); |
|
144
|
|
|
if ($value != 'y') { |
|
145
|
|
|
$this->exitGenerator(); |
|
146
|
|
|
return; |
|
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
$this->start(); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
protected function exitGenerator($msg = 'Quitting Bye bye.') |
|
153
|
|
|
{ |
|
154
|
|
|
$this->output->writeln($msg); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
protected function makeLineRequest($params) |
|
158
|
|
|
{ |
|
159
|
|
|
//nesting loop protection |
|
160
|
|
|
if ($this->getNestingLevel() < 0) { |
|
161
|
|
|
rewind($this->output->getStream()); |
|
|
|
|
|
|
162
|
|
|
$display = stream_get_contents($this->output->getStream()); |
|
|
|
|
|
|
163
|
|
|
throw new \Exception($display); |
|
164
|
|
|
} |
|
165
|
|
|
$this->nestingLevel--; |
|
166
|
|
|
|
|
|
|
|
|
|
167
|
|
|
$this->output->writeln($params['name']); |
|
168
|
|
|
$Question = new Question('<comment>Input' . self::INPUT_OPEN . $params['no'] . self::INPUT_CLOSE . ' : </comment>', ''); |
|
|
|
|
|
|
169
|
|
|
$value = $this->dialog->ask($this->input, $this->output, $Question); |
|
170
|
|
|
$value = trim($value); |
|
171
|
|
|
if ($value === self::STOP_PROCESS) { |
|
172
|
|
|
return false; |
|
173
|
|
|
} |
|
174
|
|
|
foreach ($params['validation'] as $key => $row) { |
|
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
if ($key == 'isRequired' && $row == true) { |
|
177
|
|
|
if ($value === '' || strlen($value) == 0) { |
|
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
$this->output->writeln('[!] Value cannot be empty.'); |
|
180
|
|
|
return $this->makeLineRequest($params); |
|
|
|
|
|
|
181
|
|
|
} |
|
182
|
|
|
} elseif ($key == 'patern' && preg_match($row, $value) == false) { |
|
|
|
|
|
|
183
|
|
|
$this->output->writeln('<error>[!] Value is not valid.</error>'); |
|
184
|
|
|
return $this->makeLineRequest($params); |
|
|
|
|
|
|
185
|
|
|
} elseif ($key == 'inArray' || $key == 'choice') { |
|
|
|
|
|
|
186
|
|
|
|
|
187
|
|
|
if (is_string($row)) { |
|
188
|
|
|
$row = $this->$row(); |
|
189
|
|
|
} |
|
190
|
|
|
if ($value == '') { |
|
191
|
|
|
return $params['value']; |
|
192
|
|
|
} |
|
193
|
|
|
if (isset($row[$value])) { |
|
194
|
|
|
if (!is_array($params['value'])) { |
|
195
|
|
|
$value = $row[$value]; |
|
196
|
|
|
continue; |
|
197
|
|
|
} |
|
198
|
|
|
$params['value'][$value] = $row[$value]; |
|
199
|
|
|
$this->output->writeln('<info>--- your entry list</info>'); |
|
200
|
|
|
foreach ($params['value'] as $subKey => $node) { |
|
201
|
|
|
$this->output->writeln('<info> - ' . $subKey . '</info>'); |
|
|
|
|
|
|
202
|
|
|
} |
|
203
|
|
|
$this->output->writeln(''); |
|
204
|
|
|
$this->output->writeln('--- Press Enter to move to the next step ---'); |
|
205
|
|
|
|
|
206
|
|
|
return $this->makeLineRequest($params); |
|
207
|
|
|
} else { |
|
208
|
|
|
$searchList = array(); |
|
209
|
|
|
$max = 16; |
|
210
|
|
|
foreach ($row as $eventKey => $eventConst) { |
|
211
|
|
|
if (strpos($eventKey, $value) !== false || strpos($eventConst, $value) !== false) { |
|
212
|
|
|
if (count($searchList) >= $max) { |
|
213
|
|
|
$searchList['-- there are more then ' . $max . ''] = ''; |
|
|
|
|
|
|
214
|
|
|
break; |
|
215
|
|
|
} |
|
216
|
|
|
$searchList[$eventKey] = $eventConst; |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
$this->output->writeln('<error>[!] No results have been found</error>'); |
|
220
|
|
|
if (!empty($searchList)) { |
|
221
|
|
|
$this->output->writeln('--- there are more then one search result'); |
|
222
|
|
|
} |
|
223
|
|
|
foreach ($searchList as $subKey => $node) { |
|
224
|
|
|
$this->output->writeln(' - ' . $subKey); |
|
|
|
|
|
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
if (!empty($searchList)) { |
|
228
|
|
|
$this->output->writeln(''); |
|
229
|
|
|
} |
|
230
|
|
|
return $this->makeLineRequest($params); |
|
|
|
|
|
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
return $value; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
protected function getNestingLevel() |
|
239
|
|
|
{ |
|
240
|
|
|
return $this->nestingLevel; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
protected function setNestingLevel($nestingLevel) |
|
244
|
|
|
{ |
|
245
|
|
|
$this->nestingLevel = $nestingLevel; |
|
246
|
|
|
} |
|
247
|
|
|
} |
|
248
|
|
|
|