3
3
namespace PHPCR \Shell \Console \Helper ;
4
4
5
5
use Symfony \Component \Console \Helper \Helper ;
6
+ use Symfony \Component \Console \Helper \TableHelper ;
6
7
use PHPCR \Query \QueryResultInterface ;
7
8
use Symfony \Component \Console \Output \OutputInterface ;
8
9
use PHPCR \PropertyType ;
@@ -20,27 +21,32 @@ public function format(QueryResultInterface $result, OutputInterface $output, $e
20
21
$ selectorNames = $ result ->getSelectorNames ();
21
22
22
23
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
+
24
28
foreach ($ selectorNames as $ selectorName ) {
25
29
$ node = $ row ->getNode ($ selectorName );
26
30
$ 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 ' ,
29
32
$ selectorName , $ node ->getPath (), $ node ->getIdentifier ()
30
33
));
31
34
35
+ $ table = new TableHelper ;
36
+ $ table ->setHeaders (array ('Name ' , 'Type ' , 'Multiple ' , 'Value ' ));
32
37
foreach ($ properties as $ key => $ value ) {
33
- $ output -> writeln ( sprintf ( ' <info>%s</info> <fg=magenta>%s%s</fg=magenta>: %s ' ,
38
+ $ table -> addRow ( array (
34
39
$ key ,
35
40
PropertyType::nameFromValue ($ value ->getType ()),
36
- $ value ->isMultiple () ? '[] ' : '' ,
41
+ $ value ->isMultiple () ? 'yes ' : 'no ' ,
37
42
$ this ->formatValue ($ value )
38
43
));
39
44
}
45
+ $ table ->render ($ output );
40
46
}
47
+ $ output ->writeln ('' );
41
48
}
42
49
43
- $ output ->writeln ('' );
44
50
$ output ->writeln (sprintf ('%s rows in set (%s sec) ' , count ($ result ->getRows ()), number_format ($ elapsed , 2 )));
45
51
}
46
52
@@ -53,17 +59,19 @@ protected function formatValue($value)
53
59
$ array = $ value ;
54
60
$ values = array ();
55
61
56
- foreach ($ array ->getValue () as $ value ) {
62
+ foreach ($ array ->getValue () as $ i => $ value ) {
57
63
if ($ value instanceof NodeInterface) {
58
- $ values [] = $ value ->getPath ();
64
+ $ value = $ value ->getPath ();
59
65
} else if (is_object ($ value )) {
60
- $ values [] = '<UNKNOWN OBJECT> ' ;
66
+ $ value = '<UNKNOWN OBJECT> ' ;
61
67
} else {
62
- $ values [] = $ value ;
68
+ $ value = $ value ;
63
69
}
70
+ $ value = '[ ' . $ i . '] ' . $ value ;
71
+ $ values [] = $ value ;
64
72
}
65
73
66
- return "\n - " . implode ("\n - " , $ values );
74
+ return implode ("\n" , $ values );
67
75
}
68
76
69
77
switch (intval ($ value ->getType ())) {
0 commit comments