11
11
use Inhere \Console \Controller ;
12
12
use Inhere \Console \IO \Input ;
13
13
use Inhere \Console \IO \Output ;
14
+ use RuntimeException ;
14
15
use Toolkit \Sys \Sys ;
16
+ use function array_filter ;
17
+ use function array_intersect ;
18
+ use function count ;
19
+ use function defined ;
20
+ use function implode ;
21
+ use function is_dir ;
22
+ use function is_file ;
23
+ use function sprintf ;
24
+ use function str_pad ;
25
+ use const PHP_EOL ;
15
26
16
27
/**
17
28
* Internal tool for toolkit development
@@ -54,7 +65,7 @@ public function listCommand(Input $input, Output $output): int
54
65
{
55
66
$ this ->checkEnv ();
56
67
57
- $ output ->colored ('Components Total: ' . \ count ($ this ->components ));
68
+ $ output ->colored ('Components Total: ' . count ($ this ->components ));
58
69
59
70
$ buffer = [];
60
71
$ showRepo = (bool )$ input ->getOpt ('show-repo ' );
@@ -65,9 +76,9 @@ public function listCommand(Input $input, Output $output): int
65
76
continue ;
66
77
}
67
78
68
- $ remote = \ sprintf ($ this ->gitUrl , self ::TYPE_HTTPS , $ component );
69
- $ component = \ str_pad ($ component , 20 );
70
- $ buffer [] = \ sprintf (' <comment>%s</comment> - %s ' , $ component , $ remote );
79
+ $ remote = sprintf ($ this ->gitUrl , self ::TYPE_HTTPS , $ component );
80
+ $ component = str_pad ($ component , 20 );
81
+ $ buffer [] = sprintf (' <comment>%s</comment> - %s ' , $ component , $ remote );
71
82
}
72
83
73
84
$ output ->writeln ($ buffer );
@@ -93,7 +104,7 @@ public function listCommand(Input $input, Output $output): int
93
104
* @param Input $input
94
105
* @param Output $output
95
106
* @return int
96
- * @throws \ RuntimeException
107
+ * @throws RuntimeException
97
108
*/
98
109
public function addCommand (Input $ input , Output $ output ): int
99
110
{
@@ -108,7 +119,7 @@ public function addCommand(Input $input, Output $output): int
108
119
$ config ['onExec ' ] = function (string $ name ) use ($ output ) {
109
120
$ libPath = $ this ->componentDir . '/libs/ ' . $ name ;
110
121
111
- if (\ is_dir ($ libPath )) {
122
+ if (is_dir ($ libPath )) {
112
123
$ output ->liteWarning ("Component cannot be repeat add: $ name " );
113
124
114
125
return false ;
@@ -138,7 +149,7 @@ public function addCommand(Input $input, Output $output): int
138
149
* @param Input $input
139
150
* @param Output $output
140
151
* @return int
141
- * @throws \ RuntimeException
152
+ * @throws RuntimeException
142
153
*/
143
154
public function pullCommand (Input $ input , Output $ output ): int
144
155
{
@@ -174,7 +185,7 @@ public function pullCommand(Input $input, Output $output): int
174
185
* @param Input $input
175
186
* @param Output $output
176
187
* @return int
177
- * @throws \ RuntimeException
188
+ * @throws RuntimeException
178
189
*/
179
190
public function pushCommand (Input $ input , Output $ output ): int
180
191
{
@@ -194,32 +205,32 @@ public function pushCommand(Input $input, Output $output): int
194
205
* @param Output $output
195
206
* @param array $config
196
207
* @return int
197
- * @throws \ RuntimeException
208
+ * @throws RuntimeException
198
209
*/
199
210
protected function runGitSubtree (Input $ input , Output $ output , array $ config ): int
200
211
{
201
212
$ this ->checkEnv ();
202
213
$ output ->writeln ("<comment>Component Directory</comment>: \n$ this ->componentDir " );
203
214
204
215
$ operate = $ config ['operate ' ];
205
- $ names = \ array_filter ($ input ->getArgs (), 'is_int ' , ARRAY_FILTER_USE_KEY );
216
+ $ names = array_filter ($ input ->getArgs (), 'is_int ' , ARRAY_FILTER_USE_KEY );
206
217
207
218
if ($ names ) {
208
219
$ back = $ names ;
209
- $ names = \ array_intersect ($ names , $ this ->components );
220
+ $ names = array_intersect ($ names , $ this ->components );
210
221
211
222
if (!$ names ) {
212
- throw new \ RuntimeException ('Invalid component name entered: ' . \ implode (', ' , $ back ));
223
+ throw new RuntimeException ('Invalid component name entered: ' . implode (', ' , $ back ));
213
224
}
214
225
} elseif ($ input ->getSameOpt (['a ' , 'all ' ], false )) {
215
226
$ names = $ this ->components ;
216
227
} else {
217
- throw new \ RuntimeException ('Please enter the name of the component that needs to be operated ' );
228
+ throw new RuntimeException ('Please enter the name of the component that needs to be operated ' );
218
229
}
219
230
220
231
$ output ->writeln ([
221
232
"<comment> {$ config ['operatedNames ' ]}</comment>: " ,
222
- ' <info> ' . \ implode (', ' , $ names ) . '</info> '
233
+ ' <info> ' . implode (', ' , $ names ) . '</info> '
223
234
]);
224
235
225
236
$ doneOne = ' OK ' ;
@@ -240,8 +251,8 @@ protected function runGitSubtree(Input $input, Output $output, array $config): i
240
251
}
241
252
242
253
$ ret = null ;
243
- $ remote = \ sprintf ($ this ->gitUrl , $ protoHost , $ name );
244
- $ command = \ sprintf ('git subtree %s --prefix=libs/%s %s master%s ' , $ operate , $ name , $ remote , $ squash );
254
+ $ remote = sprintf ($ this ->gitUrl , $ protoHost , $ name );
255
+ $ command = sprintf ('git subtree %s --prefix=libs/%s %s master%s ' , $ operate , $ name , $ remote , $ squash );
245
256
246
257
$ output ->writeln ("> <cyan> $ command</cyan> " );
247
258
$ output ->write ("{$ config ['doing ' ]} ' $ name' ... " , false );
@@ -251,18 +262,18 @@ protected function runGitSubtree(Input $input, Output $output, array $config): i
251
262
[$ code , $ ret , $ err ] = Sys::run ($ command , $ workDir );
252
263
253
264
if ($ code !== 0 ) {
254
- throw new \ RuntimeException ("Exec command failed. command: $ command error: $ err \nreturn: \n$ ret " );
265
+ throw new RuntimeException ("Exec command failed. command: $ command error: $ err \nreturn: \n$ ret " );
255
266
}
256
267
}
257
268
258
269
$ output ->colored ($ doneOne , 'success ' );
259
270
260
271
if ($ ret && $ input ->getOpt ('show-result ' )) {
261
- $ output ->writeln (\ PHP_EOL . $ ret );
272
+ $ output ->writeln (PHP_EOL . $ ret );
262
273
}
263
274
}
264
275
265
- $ output ->colored (\ sprintf ($ config ['done ' ], \ count ($ names )), 'success ' );
276
+ $ output ->colored (sprintf ($ config ['done ' ], count ($ names )), 'success ' );
266
277
267
278
return 0 ;
268
279
}
@@ -284,7 +295,7 @@ protected function runGitSubtree(Input $input, Output $output, array $config): i
284
295
* @param Input $input
285
296
* @param Output $output
286
297
* @return int
287
- * @throws \ RuntimeException
298
+ * @throws RuntimeException
288
299
*/
289
300
public function genApiCommand (Input $ input , Output $ output ): int
290
301
{
@@ -298,7 +309,7 @@ public function genApiCommand(Input $input, Output $output): int
298
309
return -1 ;
299
310
}
300
311
301
- if (!\ is_file ($ samiPath )) {
312
+ if (!is_file ($ samiPath )) {
302
313
$ output ->colored ('The sami.phar file is not exists! File: ' . $ samiPath , 'error ' );
303
314
304
315
return -1 ;
@@ -313,7 +324,7 @@ public function genApiCommand(Input $input, Output $output): int
313
324
}
314
325
315
326
// php ~/Workspace/php/tools/sami.phar render --force
316
- $ command = \ sprintf (
327
+ $ command = sprintf (
317
328
'php ~/Workspace/php/tools/sami.phar %s %s%s ' ,
318
329
'update ' ,
319
330
$ config ,
@@ -327,11 +338,11 @@ public function genApiCommand(Input $input, Output $output): int
327
338
[$ code , $ ret ,] = Sys::run ($ command , $ workDir );
328
339
329
340
if ($ code !== 0 ) {
330
- throw new \ RuntimeException ("Exec command failed. command: $ command return: \n$ ret " );
341
+ throw new RuntimeException ("Exec command failed. command: $ command return: \n$ ret " );
331
342
}
332
343
333
344
if ($ input ->getOpt ('show-result ' )) {
334
- $ output ->writeln (\ PHP_EOL . $ ret );
345
+ $ output ->writeln (PHP_EOL . $ ret );
335
346
}
336
347
}
337
348
@@ -342,15 +353,15 @@ public function genApiCommand(Input $input, Output $output): int
342
353
343
354
private function checkEnv (): void
344
355
{
345
- if (!\ defined ('TOOLKIT_DIR ' ) || !TOOLKIT_DIR ) {
356
+ if (!defined ('TOOLKIT_DIR ' ) || !TOOLKIT_DIR ) {
346
357
$ this ->writeln ('<error>Missing the TOOLKIT_DIR define</error> ' , true );
347
358
}
348
359
349
360
$ this ->componentDir = TOOLKIT_DIR ;
350
361
351
362
$ file = TOOLKIT_DIR . '/components.inc ' ;
352
363
353
- if (!\ is_file ($ file )) {
364
+ if (!is_file ($ file )) {
354
365
$ this ->writeln ('<error>Missing the components config.</error> ' , true );
355
366
}
356
367
0 commit comments