@@ -38,6 +38,7 @@ class SymfonyStyle extends OutputStyle
38
38
public const MAX_LINE_LENGTH = 120 ;
39
39
40
40
private $ input ;
41
+ private $ output ;
41
42
private $ questionHelper ;
42
43
private $ progressBar ;
43
44
private $ lineLength ;
@@ -51,7 +52,7 @@ public function __construct(InputInterface $input, OutputInterface $output)
51
52
$ width = (new Terminal ())->getWidth () ?: self ::MAX_LINE_LENGTH ;
52
53
$ this ->lineLength = min ($ width - (int ) (\DIRECTORY_SEPARATOR === '\\' ), self ::MAX_LINE_LENGTH );
53
54
54
- parent ::__construct ($ output );
55
+ parent ::__construct ($ this -> output = $ output );
55
56
}
56
57
57
58
/**
@@ -186,15 +187,12 @@ public function caution($message)
186
187
*/
187
188
public function table (array $ headers , array $ rows )
188
189
{
189
- $ style = clone Table::getStyleDefinition ('symfony-style-guide ' );
190
- $ style ->setCellHeaderFormat ('<info>%s</info> ' );
191
-
192
- $ table = new Table ($ this );
193
- $ table ->setHeaders ($ headers );
194
- $ table ->setRows ($ rows );
195
- $ table ->setStyle ($ style );
190
+ $ this ->createTable ()
191
+ ->setHeaders ($ headers )
192
+ ->setRows ($ rows )
193
+ ->render ()
194
+ ;
196
195
197
- $ table ->render ();
198
196
$ this ->newLine ();
199
197
}
200
198
@@ -203,16 +201,13 @@ public function table(array $headers, array $rows)
203
201
*/
204
202
public function horizontalTable (array $ headers , array $ rows )
205
203
{
206
- $ style = clone Table::getStyleDefinition ('symfony-style-guide ' );
207
- $ style ->setCellHeaderFormat ('<info>%s</info> ' );
204
+ $ this ->createTable ()
205
+ ->setHorizontal (true )
206
+ ->setHeaders ($ headers )
207
+ ->setRows ($ rows )
208
+ ->render ()
209
+ ;
208
210
209
- $ table = new Table ($ this );
210
- $ table ->setHeaders ($ headers );
211
- $ table ->setRows ($ rows );
212
- $ table ->setStyle ($ style );
213
- $ table ->setHorizontal (true );
214
-
215
- $ table ->render ();
216
211
$ this ->newLine ();
217
212
}
218
213
@@ -228,10 +223,6 @@ public function horizontalTable(array $headers, array $rows)
228
223
*/
229
224
public function definitionList (...$ list )
230
225
{
231
- $ style = clone Table::getStyleDefinition ('symfony-style-guide ' );
232
- $ style ->setCellHeaderFormat ('<info>%s</info> ' );
233
-
234
- $ table = new Table ($ this );
235
226
$ headers = [];
236
227
$ row = [];
237
228
foreach ($ list as $ value ) {
@@ -252,13 +243,7 @@ public function definitionList(...$list)
252
243
$ row [] = current ($ value );
253
244
}
254
245
255
- $ table ->setHeaders ($ headers );
256
- $ table ->setRows ([$ row ]);
257
- $ table ->setHorizontal ();
258
- $ table ->setStyle ($ style );
259
-
260
- $ table ->render ();
261
- $ this ->newLine ();
246
+ $ this ->horizontalTable ($ headers , [$ row ]);
262
247
}
263
248
264
249
/**
@@ -421,6 +406,14 @@ public function getErrorStyle()
421
406
return new self ($ this ->input , $ this ->getErrorOutput ());
422
407
}
423
408
409
+ public function createTable (): Table
410
+ {
411
+ $ style = clone Table::getStyleDefinition ('symfony-style-guide ' );
412
+ $ style ->setCellHeaderFormat ('<info>%s</info> ' );
413
+
414
+ return (new Table ($ this ->output ))->setStyle ($ style );
415
+ }
416
+
424
417
private function getProgressBar (): ProgressBar
425
418
{
426
419
if (!$ this ->progressBar ) {
0 commit comments