@@ -105,16 +105,15 @@ protected function describeRoute(Route $route, array $options = array())
105
105
*/
106
106
protected function describeContainerParameters (ParameterBag $ parameters , array $ options = array ())
107
107
{
108
- $ table = new Table ($ this ->getOutput ());
109
- $ table ->setStyle ('compact ' );
110
- $ table ->setHeaders (array ('Parameter ' , 'Value ' ));
108
+ $ tableHeaders = array ('Parameter ' , 'Value ' );
111
109
110
+ $ tableRows = array ();
112
111
foreach ($ this ->sortParameters ($ parameters ) as $ parameter => $ value ) {
113
- $ table -> addRow ( array ($ parameter , $ this ->formatParameter ($ value) ));
112
+ $ tableRows [] = array ($ parameter , $ this ->formatParameter ($ value ));
114
113
}
115
114
116
- $ this -> writeText ( $ this -> formatSection ( ' container ' , ' List of parameters ' ). "\n" , $ options );
117
- $ table -> render ( );
115
+ $ options [ ' output ' ]-> title ( ' Symfony Container Parameters ' );
116
+ $ options [ ' output ' ]-> table ( $ tableHeaders , $ tableRows );
118
117
}
119
118
120
119
/**
@@ -123,15 +122,17 @@ protected function describeContainerParameters(ParameterBag $parameters, array $
123
122
protected function describeContainerTags (ContainerBuilder $ builder , array $ options = array ())
124
123
{
125
124
$ showPrivate = isset ($ options ['show_private ' ]) && $ options ['show_private ' ];
126
- $ description = array ($ this ->formatSection ('container ' , 'Tagged services ' ));
127
125
128
- foreach ($ this -> findDefinitionsByTag ( $ builder , $ showPrivate) as $ tag => $ definitions ) {
129
- $ description [] = $ this -> formatSection ( ' tag ' , $ tag );
130
- $ description = array_merge ( $ description , array_keys ( $ definitions ));
131
- $ description [] = '' ;
126
+ if ($ showPrivate ) {
127
+ $ options [ ' output ' ]-> title ( ' Symfony Container Public and Private Tags ' );
128
+ } else {
129
+ $ options [ ' output ' ]-> title ( ' Symfony Container Public Tags ' ) ;
132
130
}
133
131
134
- $ this ->writeText (implode ("\n" , $ description ), $ options );
132
+ foreach ($ this ->findDefinitionsByTag ($ builder , $ showPrivate ) as $ tag => $ definitions ) {
133
+ $ options ['output ' ]->section (sprintf ('"%s" tag ' , $ tag ));
134
+ $ options ['output ' ]->listing (array_keys ($ definitions ));
135
+ }
135
136
}
136
137
137
138
/**
@@ -148,11 +149,13 @@ protected function describeContainerService($service, array $options = array())
148
149
} elseif ($ service instanceof Definition) {
149
150
$ this ->describeContainerDefinition ($ service , $ options );
150
151
} else {
151
- $ description = $ this ->formatSection ('container ' , sprintf ('Information for service <info>%s</info> ' , $ options ['id ' ]))
152
- ."\n" .sprintf ('<comment>Service Id</comment> %s ' , isset ($ options ['id ' ]) ? $ options ['id ' ] : '- ' )
153
- ."\n" .sprintf ('<comment>Class</comment> %s ' , get_class ($ service ));
154
-
155
- $ this ->writeText ($ description , $ options );
152
+ $ options ['output ' ]->title (sprintf ('Information for Service "<info>%s</info>" ' , $ options ['id ' ]));
153
+ $ options ['output ' ]->table (
154
+ array ('Service ID ' , 'Class ' ),
155
+ array (
156
+ array (isset ($ options ['id ' ]) ? $ options ['id ' ] : '- ' , get_class ($ service )),
157
+ )
158
+ );
156
159
}
157
160
}
158
161
@@ -165,16 +168,16 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
165
168
$ showTag = isset ($ options ['tag ' ]) ? $ options ['tag ' ] : null ;
166
169
167
170
if ($ showPrivate ) {
168
- $ label = '<comment> Public</comment> and <comment>private</comment> services ' ;
171
+ $ title = 'Symfony Container Public and Private Services ' ;
169
172
} else {
170
- $ label = '<comment> Public</comment> services ' ;
173
+ $ title = 'Symfony Container Public Services ' ;
171
174
}
172
175
173
176
if ($ showTag ) {
174
- $ label .= ' with tag <info> ' . $ options ['tag ' ]. ' </info> ' ;
177
+ $ title .= sprintf ( ' Tagged with "%s" Tag ' , $ options ['tag ' ]) ;
175
178
}
176
179
177
- $ this -> writeText ( $ this -> formatSection ( ' container ' , $ label ). "\n" , $ options );
180
+ $ options [ ' output ' ]-> title ( $ title );
178
181
179
182
$ serviceIds = isset ($ options ['tag ' ]) && $ options ['tag ' ] ? array_keys ($ builder ->findTaggedServiceIds ($ options ['tag ' ])) : $ builder ->getServiceIds ();
180
183
$ maxTags = array ();
@@ -206,10 +209,8 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
206
209
$ tagsCount = count ($ maxTags );
207
210
$ tagsNames = array_keys ($ maxTags );
208
211
209
- $ table = new Table ($ this ->getOutput ());
210
- $ table ->setStyle ('compact ' );
211
- $ table ->setHeaders (array_merge (array ('Service ID ' ), $ tagsNames , array ('Class name ' )));
212
-
212
+ $ tableHeaders = array_merge (array ('Service ID ' ), $ tagsNames , array ('Class name ' ));
213
+ $ tableRows = array ();
213
214
foreach ($ this ->sortServiceIds ($ serviceIds ) as $ serviceId ) {
214
215
$ definition = $ this ->resolveServiceDefinition ($ builder , $ serviceId );
215
216
if ($ definition instanceof Definition) {
@@ -220,112 +221,125 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o
220
221
$ tagValues [] = isset ($ tag [$ tagName ]) ? $ tag [$ tagName ] : '' ;
221
222
}
222
223
if (0 === $ key ) {
223
- $ table -> addRow ( array_merge (array ($ serviceId ), $ tagValues , array ($ definition ->getClass () )));
224
+ $ tableRows [] = array_merge (array ($ serviceId ), $ tagValues , array ($ definition ->getClass ()));
224
225
} else {
225
- $ table -> addRow ( array_merge (array (' " ' ), $ tagValues , array ('' ) ));
226
+ $ tableRows [] = array_merge (array (' " ' ), $ tagValues , array ('' ));
226
227
}
227
228
}
228
229
} else {
229
- $ table -> addRow ( array ($ serviceId , $ definition ->getClass () ));
230
+ $ tableRows [] = array ($ serviceId , $ definition ->getClass ());
230
231
}
231
232
} elseif ($ definition instanceof Alias) {
232
233
$ alias = $ definition ;
233
- $ table -> addRow ( array_merge (array ($ serviceId , sprintf ('alias for "%s" ' , $ alias )), $ tagsCount ? array_fill (0 , $ tagsCount , '' ) : array () ));
234
+ $ tableRows [] = array_merge (array ($ serviceId , sprintf ('alias for "%s" ' , $ alias )), $ tagsCount ? array_fill (0 , $ tagsCount , '' ) : array ());
234
235
} else {
235
236
// we have no information (happens with "service_container")
236
- $ table -> addRow ( array_merge (array ($ serviceId , get_class ($ definition )), $ tagsCount ? array_fill (0 , $ tagsCount , '' ) : array () ));
237
+ $ tableRows [] = array_merge (array ($ serviceId , get_class ($ definition )), $ tagsCount ? array_fill (0 , $ tagsCount , '' ) : array ());
237
238
}
238
239
}
239
240
240
- $ table -> render ( );
241
+ $ options [ ' output ' ]-> table ( $ tableHeaders , $ tableRows );
241
242
}
242
243
243
244
/**
244
245
* {@inheritdoc}
245
246
*/
246
247
protected function describeContainerDefinition (Definition $ definition , array $ options = array ())
247
248
{
248
- $ description = isset ($ options ['id ' ])
249
- ? array ( $ this -> formatSection ( ' container ' , sprintf ('Information for service <info>%s</info> ' , $ options ['id ' ])))
250
- : array ();
249
+ if ( isset ($ options ['id ' ])) {
250
+ $ options [ ' output ' ]-> title ( sprintf ('Information for Service " <info>%s</info>" ' , $ options ['id ' ]));
251
+ }
251
252
252
- $ description [] = sprintf ('<comment>Service Id</comment> %s ' , isset ($ options ['id ' ]) ? $ options ['id ' ] : '- ' );
253
- $ description [] = sprintf ('<comment>Class</comment> %s ' , $ definition ->getClass () ?: '- ' );
253
+ $ tableHeaders = array ('Option ' , 'Value ' );
254
+
255
+ $ tableRows [] = array ('Service ID ' , isset ($ options ['id ' ]) ? $ options ['id ' ] : '- ' );
256
+ $ tableRows [] = array ('Class ' , $ definition ->getClass () ?: '- ' );
254
257
255
258
$ tags = $ definition ->getTags ();
256
259
if (count ($ tags )) {
257
- $ description [] = '<comment>Tags</comment> ' ;
260
+ $ tagInformation = '' ;
258
261
foreach ($ tags as $ tagName => $ tagData ) {
259
- foreach ($ tagData as $ parameters ) {
260
- $ description [] = sprintf ( ' - %-30s (%s) ' , $ tagName , implode ( ' , ' , array_map (function ($ key , $ value ) {
262
+ foreach ($ tagData as $ tagParameters ) {
263
+ $ parameters = array_map (function ($ key , $ value ) {
261
264
return sprintf ('<info>%s</info>: %s ' , $ key , $ value );
262
- }, array_keys ($ parameters ), array_values ($ parameters ))));
265
+ }, array_keys ($ tagParameters ), array_values ($ tagParameters ));
266
+ $ parameters = implode (', ' , $ parameters );
267
+
268
+ if ('' === $ parameters ) {
269
+ $ tagInformation .= sprintf ('%s ' , $ tagName );
270
+ } else {
271
+ $ tagInformation .= sprintf ('%s (%s) ' , $ tagName , $ parameters );
272
+ }
263
273
}
264
274
}
265
275
} else {
266
- $ description [] = '<comment>Tags</comment> - ' ;
276
+ $ tagInformation = '- ' ;
267
277
}
278
+ $ tableRows [] = array ('Tags ' , $ tagInformation );
279
+
280
+ $ tableRows [] = array ('Scope ' , $ definition ->getScope (false ));
281
+ $ tableRows [] = array ('Public ' , $ definition ->isPublic () ? 'yes ' : 'no ' );
282
+ $ tableRows [] = array ('Synthetic ' , $ definition ->isSynthetic () ? 'yes ' : 'no ' );
283
+ $ tableRows [] = array ('Lazy ' , $ definition ->isLazy () ? 'yes ' : 'no ' );
268
284
269
- $ description [] = sprintf ('<comment>Scope</comment> %s ' , $ definition ->getScope (false ));
270
- $ description [] = sprintf ('<comment>Public</comment> %s ' , $ definition ->isPublic () ? 'yes ' : 'no ' );
271
- $ description [] = sprintf ('<comment>Synthetic</comment> %s ' , $ definition ->isSynthetic () ? 'yes ' : 'no ' );
272
- $ description [] = sprintf ('<comment>Lazy</comment> %s ' , $ definition ->isLazy () ? 'yes ' : 'no ' );
273
- if (method_exists ($ definition , 'isShared ' )) {
274
- $ description [] = sprintf ('<comment>Shared</comment> %s ' , $ definition ->isShared () ? 'yes ' : 'no ' );
275
- }
276
285
if (method_exists ($ definition , 'isSynchronized ' )) {
277
- $ description [] = sprintf ( ' <comment> Synchronized</comment> %s ' , $ definition ->isSynchronized (false ) ? 'yes ' : 'no ' );
286
+ $ tableRows [] = array ( ' Synchronized ' , $ definition ->isSynchronized (false ) ? 'yes ' : 'no ' );
278
287
}
279
- $ description [] = sprintf ( ' <comment> Abstract</comment> %s ' , $ definition ->isAbstract () ? 'yes ' : 'no ' );
288
+ $ tableRows [] = array ( ' Abstract ' , $ definition ->isAbstract () ? 'yes ' : 'no ' );
280
289
281
290
if ($ definition ->getFile ()) {
282
- $ description [] = sprintf ( ' <comment> Required File</comment> %s ' , $ definition ->getFile () ?: '- ' );
291
+ $ tableRows [] = array ( ' Required File ' , $ definition ->getFile () ? $ definition -> getFile () : '- ' );
283
292
}
284
293
285
294
if ($ definition ->getFactoryClass (false )) {
286
- $ description [] = sprintf ( ' <comment> Factory Class</comment> %s ' , $ definition ->getFactoryClass (false ));
295
+ $ tableRows [] = array ( ' Factory Class ' , $ definition ->getFactoryClass (false ));
287
296
}
288
297
289
298
if ($ definition ->getFactoryService (false )) {
290
- $ description [] = sprintf ( ' <comment> Factory Service</comment> %s ' , $ definition ->getFactoryService (false ));
299
+ $ tableRows [] = array ( ' Factory Service ' , $ definition ->getFactoryService (false ));
291
300
}
292
301
293
302
if ($ definition ->getFactoryMethod (false )) {
294
- $ description [] = sprintf ( ' <comment> Factory Method</comment> %s ' , $ definition ->getFactoryMethod (false ));
303
+ $ tableRows [] = array ( ' Factory Method ' , $ definition ->getFactoryMethod (false ));
295
304
}
296
305
297
306
if ($ factory = $ definition ->getFactory ()) {
298
307
if (is_array ($ factory )) {
299
308
if ($ factory [0 ] instanceof Reference) {
300
- $ description [] = sprintf ( ' <comment> Factory Service</comment> %s ' , $ factory [0 ]);
309
+ $ tableRows [] = array ( ' Factory Service ' , $ factory [0 ]);
301
310
} elseif ($ factory [0 ] instanceof Definition) {
302
311
throw new \InvalidArgumentException ('Factory is not describable. ' );
303
312
} else {
304
- $ description [] = sprintf ( ' <comment> Factory Class</comment> %s ' , $ factory [0 ]);
313
+ $ tableRows [] = array ( ' Factory Class ' , $ factory [0 ]);
305
314
}
306
- $ description [] = sprintf ( ' <comment> Factory Method</comment> %s ' , $ factory [1 ]);
315
+ $ tableRows [] = array ( ' Factory Method ' , $ factory [1 ]);
307
316
} else {
308
- $ description [] = sprintf ( ' <comment> Factory Function</comment> %s ' , $ factory );
317
+ $ tableRows [] = array ( ' Factory Function ' , $ factory );
309
318
}
310
319
}
311
320
312
- $ this -> writeText ( implode ( "\n" , $ description ). "\n" , $ options );
321
+ $ options [ ' output ' ]-> table ( $ tableHeaders , $ tableRows );
313
322
}
314
323
315
324
/**
316
325
* {@inheritdoc}
317
326
*/
318
327
protected function describeContainerAlias (Alias $ alias , array $ options = array ())
319
328
{
320
- $ this -> writeText (sprintf ("This service is an alias for the service <info>%s</info> \n" , (string ) $ alias ), $ options );
329
+ $ options [ ' output ' ]-> comment (sprintf ("This service is an alias for the service <info>%s</info> \n" , (string ) $ alias ));
321
330
}
322
331
323
332
/**
324
333
* {@inheritdoc}
325
334
*/
326
335
protected function describeContainerParameter ($ parameter , array $ options = array ())
327
336
{
328
- $ this ->writeText ($ this ->formatParameter ($ parameter ), $ options );
337
+ $ options ['output ' ]->table (
338
+ array ('Parameter ' , 'Value ' ),
339
+ array (
340
+ array ($ options ['parameter ' ], $ this ->formatParameter ($ parameter ),
341
+ ),
342
+ ));
329
343
}
330
344
331
345
/**
@@ -344,16 +358,33 @@ protected function describeEventDispatcherListeners(EventDispatcherInterface $ev
344
358
345
359
$ this ->writeText ($ this ->formatSection ('event_dispatcher ' , $ label )."\n" , $ options );
346
360
347
- $ registeredListeners = $ eventDispatcher ->getListeners ($ event, true );
361
+ $ registeredListeners = $ eventDispatcher ->getListeners ($ event );
348
362
349
363
if (null !== $ event ) {
350
364
$ this ->writeText ("\n" );
351
- $ this ->renderEventListenerTable ($ registeredListeners );
365
+ $ table = new Table ($ this ->getOutput ());
366
+ $ table ->getStyle ()->setCellHeaderFormat ('%s ' );
367
+ $ table ->setHeaders (array ('Order ' , 'Callable ' ));
368
+
369
+ foreach ($ registeredListeners as $ order => $ listener ) {
370
+ $ table ->addRow (array (sprintf ('#%d ' , $ order + 1 ), $ this ->formatCallable ($ listener )));
371
+ }
372
+
373
+ $ table ->render ();
352
374
} else {
353
375
ksort ($ registeredListeners );
354
376
foreach ($ registeredListeners as $ eventListened => $ eventListeners ) {
355
377
$ this ->writeText (sprintf ("\n<info>[Event]</info> %s \n" , $ eventListened ), $ options );
356
- $ this ->renderEventListenerTable ($ eventListeners );
378
+
379
+ $ table = new Table ($ this ->getOutput ());
380
+ $ table ->getStyle ()->setCellHeaderFormat ('%s ' );
381
+ $ table ->setHeaders (array ('Order ' , 'Callable ' ));
382
+
383
+ foreach ($ eventListeners as $ order => $ eventListener ) {
384
+ $ table ->addRow (array (sprintf ('#%d ' , $ order + 1 ), $ this ->formatCallable ($ eventListener )));
385
+ }
386
+
387
+ $ table ->render ();
357
388
}
358
389
}
359
390
}
0 commit comments