1717use phpbb \skeleton \helper \packager ;
1818use phpbb \skeleton \helper \validator ;
1919use phpbb \user ;
20- use Symfony \Component \Console \Helper \DialogHelper ;
20+ use Symfony \Component \Console \Helper \QuestionHelper ;
2121use Symfony \Component \Console \Input \InputInterface ;
2222use Symfony \Component \Console \Output \OutputInterface ;
23+ use Symfony \Component \Console \Question \ConfirmationQuestion ;
24+ use Symfony \Component \Console \Question \Question ;
2325
2426class create extends command
2527{
28+ /** @var array user input data array */
2629 protected $ data = array ();
2730
28- /** @var validator */
29- protected $ validator ;
31+ /** @var QuestionHelper $helper */
32+ protected $ helper ;
33+
34+ /** @var InputInterface */
35+ protected $ input ;
36+
37+ /** @var OutputInterface */
38+ protected $ output ;
3039
3140 /** @var packager */
3241 protected $ packager ;
3342
43+ /** @var validator */
44+ protected $ validator ;
45+
3446 /**
3547 * Constructor
3648 *
@@ -84,56 +96,52 @@ protected function execute(InputInterface $input, OutputInterface $output)
8496 */
8597 protected function interact (InputInterface $ input , OutputInterface $ output )
8698 {
87- /** @var DialogHelper $dialog */
88- $ dialog = $ this ->getHelper ('dialog ' );
99+ $ this ->input = $ input ;
100+ $ this ->output = $ output ;
101+
102+ $ this ->helper = $ this ->getHelper ('question ' );
89103
90104 $ output ->writeln ($ this ->user ->lang ('SKELETON_CLI_COMPOSER_QUESTIONS ' ));
91- $ this ->get_composer_data ($ dialog , $ output );
105+ $ this ->get_composer_data ();
92106
93107 $ output ->writeln ($ this ->user ->lang ('SKELETON_CLI_COMPONENT_QUESTIONS ' ));
94- $ this ->get_component_data ($ dialog , $ output );
108+ $ this ->get_component_data ();
95109 }
96110
97111 /**
98- * @param DialogHelper $dialog
99- * @param OutputInterface $output
112+ * Get composer data from the user
100113 */
101- protected function get_composer_data (DialogHelper $ dialog , OutputInterface $ output )
114+ protected function get_composer_data ()
102115 {
103116 $ dialog_questions = $ this ->packager ->get_composer_dialog_values ();
104117 foreach ($ dialog_questions ['extension ' ] as $ value => $ default )
105118 {
106- $ this ->data ['extension ' ][$ value ] = $ this ->get_user_input ($ dialog , $ output , $ value , $ default );
119+ $ this ->data ['extension ' ][$ value ] = $ this ->get_user_input ($ value , $ default );
107120 }
108121
109- $ num_authors = $ dialog ->askAndValidate (
110- $ output ,
111- $ this ->user ->lang ('SKELETON_QUESTION_NUM_AUTHORS ' ) . $ this ->user ->lang ('COLON ' ),
112- array ($ this ->validator , 'validate_num_authors ' ),
113- false ,
114- 1
115- );
122+ $ question = new Question ($ this ->user ->lang ('SKELETON_QUESTION_NUM_AUTHORS ' ) . $ this ->user ->lang ('COLON ' ), 1 );
123+ $ question ->setValidator (array ($ this ->validator , 'validate_num_authors ' ));
124+ $ num_authors = $ this ->helper ->ask ($ this ->input , $ this ->output , $ question );
116125
117126 $ this ->data ['authors ' ] = array ();
118127 for ($ i = 0 ; $ i < $ num_authors ; $ i ++)
119128 {
120129 foreach ($ dialog_questions ['author ' ] as $ value => $ default )
121130 {
122- $ this ->data ['authors ' ][$ i ][$ value ] = $ this ->get_user_input ($ dialog , $ output , $ value , $ default );
131+ $ this ->data ['authors ' ][$ i ][$ value ] = $ this ->get_user_input ($ value , $ default );
123132 }
124133 }
125134
126135 foreach ($ dialog_questions ['requirements ' ] as $ value => $ default )
127136 {
128- $ this ->data ['requirements ' ][$ value ] = $ this ->get_user_input ($ dialog , $ output , $ value , $ default );
137+ $ this ->data ['requirements ' ][$ value ] = $ this ->get_user_input ($ value , $ default );
129138 }
130139 }
131140
132141 /**
133- * @param DialogHelper $dialog
134- * @param OutputInterface $output
142+ * Get component data from the user
135143 */
136- protected function get_component_data (DialogHelper $ dialog , OutputInterface $ output )
144+ protected function get_component_data ()
137145 {
138146 $ components = $ this ->packager ->get_component_dialog_values ();
139147 foreach ($ components as $ component => $ details )
@@ -147,44 +155,36 @@ protected function get_component_data(DialogHelper $dialog, OutputInterface $out
147155 }
148156 }
149157
150- $ this ->data ['components ' ][$ component ] = $ this ->get_user_input ($ dialog , $ output , 'component_ ' . $ component , $ details ['default ' ]);
158+ $ this ->data ['components ' ][$ component ] = $ this ->get_user_input ('component_ ' . $ component , $ details ['default ' ]);
151159 }
152160 }
153161
154162 /**
155- * @param DialogHelper $dialog
156- * @param OutputInterface $output
163+ * Helper for getting user input
164+ *
157165 * @param string $value
158166 * @param mixed $default
159167 * @return mixed|string
160168 */
161- protected function get_user_input (DialogHelper $ dialog , OutputInterface $ output , $ value , $ default )
169+ protected function get_user_input ($ value , $ default )
162170 {
171+ $ dialog = $ this ->user ->lang ('SKELETON_QUESTION_ ' . strtoupper ($ value )) . $ this ->user ->lang ('COLON ' );
172+
163173 if (method_exists ($ this ->validator , 'validate_ ' . $ value ))
164174 {
165- $ return_value = $ dialog ->askAndValidate (
166- $ output ,
167- $ this ->user ->lang ('SKELETON_QUESTION_ ' . strtoupper ($ value )) . $ this ->user ->lang ('COLON ' ),
168- array ($ this ->validator , 'validate_ ' . $ value ),
169- false ,
170- $ default
171- );
175+ $ question = new Question ($ dialog , $ default );
176+ $ question ->setValidator (array ($ this ->validator , 'validate_ ' . $ value ));
177+ $ return_value = $ this ->helper ->ask ($ this ->input , $ this ->output , $ question );
172178 }
173179 else if (is_bool ($ default ))
174180 {
175- $ return_value = $ dialog ->askConfirmation (
176- $ output ,
177- $ this ->user ->lang ('SKELETON_QUESTION_ ' . strtoupper ($ value )) . $ this ->user ->lang ('COLON ' ),
178- $ default
179- );
181+ $ question = new ConfirmationQuestion ($ dialog , $ default );
182+ $ return_value = $ this ->helper ->ask ($ this ->input , $ this ->output , $ question );
180183 }
181184 else
182185 {
183- $ return_value = $ dialog ->ask (
184- $ output ,
185- $ this ->user ->lang ('SKELETON_QUESTION_ ' . strtoupper ($ value )) . $ this ->user ->lang ('COLON ' ),
186- $ default
187- );
186+ $ question = new Question ($ dialog , $ default );
187+ $ return_value = $ this ->helper ->ask ($ this ->input , $ this ->output , $ question );
188188 }
189189
190190 return $ return_value ;
0 commit comments