33namespace PHPCR \Shell \Console \Helper ;
44
55use Symfony \Component \Console \Helper \Helper ;
6+ use Symfony \Component \Console \Helper \TableHelper ;
67use PHPCR \Query \QueryResultInterface ;
78use Symfony \Component \Console \Output \OutputInterface ;
89use PHPCR \PropertyType ;
@@ -20,27 +21,32 @@ public function format(QueryResultInterface $result, OutputInterface $output, $e
2021 $ selectorNames = $ result ->getSelectorNames ();
2122
2223 foreach ($ result ->getRows () as $ i => $ row ) {
23- $ output ->writeln (sprintf ('%s ---- ' , $ i + 1 ));
24+ $ output ->writeln (sprintf ($ str = '| <info>Row:</info> #%d <info>Score:</info> %d ' ,
25+ $ i , $ row ->getScore ()
26+ ));
27+
2428 foreach ($ selectorNames as $ selectorName ) {
2529 $ node = $ row ->getNode ($ selectorName );
2630 $ properties = $ node ->getProperties ();
27- $ output ->writeln (sprintf (
28- ' [%s] [path:<comment>%s</comment>] [uid:<info>%s</info>] ' ,
31+ $ output ->writeln (sprintf ('| <info>selector:</info> %s <info>path:</info> %s <info>uid:</info> %s ' ,
2932 $ selectorName , $ node ->getPath (), $ node ->getIdentifier ()
3033 ));
3134
35+ $ table = new TableHelper ;
36+ $ table ->setHeaders (array ('Name ' , 'Type ' , 'Multiple ' , 'Value ' ));
3237 foreach ($ properties as $ key => $ value ) {
33- $ output -> writeln ( sprintf ( ' <info>%s</info> <fg=magenta>%s%s</fg=magenta>: %s ' ,
38+ $ table -> addRow ( array (
3439 $ key ,
3540 PropertyType::nameFromValue ($ value ->getType ()),
36- $ value ->isMultiple () ? '[] ' : '' ,
41+ $ value ->isMultiple () ? 'yes ' : 'no ' ,
3742 $ this ->formatValue ($ value )
3843 ));
3944 }
45+ $ table ->render ($ output );
4046 }
47+ $ output ->writeln ('' );
4148 }
4249
43- $ output ->writeln ('' );
4450 $ output ->writeln (sprintf ('%s rows in set (%s sec) ' , count ($ result ->getRows ()), number_format ($ elapsed , 2 )));
4551 }
4652
@@ -53,17 +59,19 @@ protected function formatValue($value)
5359 $ array = $ value ;
5460 $ values = array ();
5561
56- foreach ($ array ->getValue () as $ value ) {
62+ foreach ($ array ->getValue () as $ i => $ value ) {
5763 if ($ value instanceof NodeInterface) {
58- $ values [] = $ value ->getPath ();
64+ $ value = $ value ->getPath ();
5965 } else if (is_object ($ value )) {
60- $ values [] = '<UNKNOWN OBJECT> ' ;
66+ $ value = '<UNKNOWN OBJECT> ' ;
6167 } else {
62- $ values [] = $ value ;
68+ $ value = $ value ;
6369 }
70+ $ value = '[ ' . $ i . '] ' . $ value ;
71+ $ values [] = $ value ;
6472 }
6573
66- return "\n - " . implode ("\n - " , $ values );
74+ return implode ("\n" , $ values );
6775 }
6876
6977 switch (intval ($ value ->getType ())) {
0 commit comments