-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcreate.php
More file actions
205 lines (177 loc) · 5.39 KB
/
create.php
File metadata and controls
205 lines (177 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\skeleton\console;
use phpbb\console\command\command;
use phpbb\language\language;
use phpbb\skeleton\helper\packager;
use phpbb\skeleton\helper\validator;
use phpbb\user;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
class create extends command
{
/** @var array user input data array */
protected $data = [];
/** @var QuestionHelper $helper */
protected $helper;
/** @var InputInterface */
protected $input;
/** @var OutputInterface */
protected $output;
/** @var language */
protected $language;
/** @var packager */
protected $packager;
/** @var validator */
protected $validator;
/**
* Constructor
*
* @param user $user
* @param language $language
* @param packager $packager
* @param validator $validator
*/
public function __construct(user $user, language $language, packager $packager, validator $validator)
{
$this->language = $language;
$this->packager = $packager;
$this->validator = $validator;
$this->language->add_lang('common', 'phpbb/skeleton');
parent::__construct($user);
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('extension:create')
->setDescription($this->language->lang('CLI_DESCRIPTION_SKELETON_CREATE'))
;
}
/**
* Executes the command extension:create.
*
* Creates an extension skeleton
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @see \phpbb\config\config::delete()
*
* @return int 0 if everything went fine, or an exit code
*
* @throws LogicException When this abstract method is not implemented
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->packager->create_extension($this->data);
$output->writeln($this->language->lang('EXTENSION_CLI_SKELETON_SUCCESS'));
return SymfonyCommand::SUCCESS;
}
/**
* Interacts with the user.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
$this->helper = $this->getHelper('question');
$output->writeln($this->language->lang('SKELETON_CLI_COMPOSER_QUESTIONS'));
$this->get_composer_data();
$output->writeln($this->language->lang('SKELETON_CLI_COMPONENT_QUESTIONS'));
$this->get_component_data();
}
/**
* Get composer data from the user
*/
protected function get_composer_data()
{
$dialog_questions = $this->packager->get_composer_dialog_values();
foreach ($dialog_questions['extension'] as $value => $default)
{
$this->data['extension'][$value] = $this->get_user_input($value, $default);
}
$question = new Question($this->language->lang('SKELETON_QUESTION_NUM_AUTHORS') . $this->language->lang('COLON'), 1);
$question->setValidator([$this->validator, 'validate_num_authors']);
$num_authors = $this->helper->ask($this->input, $this->output, $question);
$this->data['authors'] = [];
for ($i = 0; $i < $num_authors; $i++)
{
foreach ($dialog_questions['author'] as $value => $default)
{
$this->data['authors'][$i][$value] = $this->get_user_input($value, $default);
}
}
foreach ($dialog_questions['requirements'] as $value => $default)
{
$this->data['requirements'][$value] = $this->get_user_input($value, $default);
}
}
/**
* Get component data from the user
*/
protected function get_component_data()
{
$components = $this->packager->get_component_dialog_values();
foreach ($components as $component => $details)
{
foreach ($details['dependencies'] as $depends)
{
if (empty($this->data['components'][$depends]))
{
$this->data['components'][$component] = false;
continue 2;
}
}
$this->data['components'][$component] = $this->get_user_input('component_' . $component, $details['default']);
}
}
/**
* Helper for getting user input
*
* @param string $value
* @param mixed $default
* @return mixed|string
*/
protected function get_user_input($value, $default)
{
$dialog = $this->language->lang('SKELETON_QUESTION_' . strtoupper($value)) . $this->language->lang('COLON');
if (method_exists($this->validator, 'validate_' . $value))
{
$question = new Question($dialog, $default);
$question->setValidator([$this->validator, 'validate_' . $value]);
$return_value = $this->helper->ask($this->input, $this->output, $question);
}
else if (is_bool($default))
{
$question = new ConfirmationQuestion($dialog, $default);
$return_value = $this->helper->ask($this->input, $this->output, $question);
}
else
{
$question = new Question($dialog, $default);
$return_value = $this->helper->ask($this->input, $this->output, $question);
}
return $return_value;
}
}