66use PHPCR \Query \QueryResultInterface ;
77use Symfony \Component \Console \Output \OutputInterface ;
88use PHPCR \PropertyType ;
9+ use PHPCR \NodeInterface ;
910
1011class ResultFormatterHelper extends Helper
1112{
@@ -14,19 +15,22 @@ public function getName()
1415 return 'result_formatter ' ;
1516 }
1617
17- public function format (QueryResultInterface $ result , OutputInterface $ output )
18+ public function format (QueryResultInterface $ result , OutputInterface $ output, $ elapsed )
1819 {
1920 $ selectorNames = $ result ->getSelectorNames ();
21+
2022 foreach ($ result ->getRows () as $ i => $ row ) {
21- $ output ->writeln ($ i );
23+ $ output ->writeln (sprintf ( ' %s ---- ' , $ i + 1 ) );
2224 foreach ($ selectorNames as $ selectorName ) {
2325 $ node = $ row ->getNode ($ selectorName );
2426 $ properties = $ node ->getProperties ();
25- $ output ->writeln (' ' . $ selectorName );
26- $ output ->writeln (' <comment> ' . $ node ->getPath ().'</comment> ' );
27+ $ output ->writeln (sprintf (
28+ ' [%s] [path:<comment>%s</comment>] [uid:<info>%s</info>] ' ,
29+ $ selectorName , $ node ->getPath (), $ node ->getIdentifier ()
30+ ));
2731
2832 foreach ($ properties as $ key => $ value ) {
29- $ output ->writeln (sprintf (' <info>%s</info> %s%s: %s ' ,
33+ $ output ->writeln (sprintf (' <info>%s</info> <fg=magenta> %s%s</fg=magenta> : %s ' ,
3034 $ key ,
3135 PropertyType::nameFromValue ($ value ->getType ()),
3236 $ value ->isMultiple () ? '[] ' : '' ,
@@ -35,6 +39,9 @@ public function format(QueryResultInterface $result, OutputInterface $output)
3539 }
3640 }
3741 }
42+
43+ $ output ->writeln ('' );
44+ $ output ->writeln (sprintf ('%s rows in set (%s sec) ' , count ($ result ->getRows ()), number_format ($ elapsed , 2 )));
3845 }
3946
4047 protected function formatValue ($ value )
@@ -43,8 +50,20 @@ protected function formatValue($value)
4350 if (empty ($ value ->getValue ())) {
4451 return '' ;
4552 }
53+ $ array = $ value ;
54+ $ values = array ();
55+
56+ foreach ($ array ->getValue () as $ value ) {
57+ if ($ value instanceof NodeInterface) {
58+ $ values [] = $ value ->getPath ();
59+ } else if (is_object ($ value )) {
60+ $ values [] = '<UNKNOWN OBJECT> ' ;
61+ } else {
62+ $ values [] = $ value ;
63+ }
64+ }
4665
47- return "\n - " . implode ("\n - " , $ value -> getvalue () );
66+ return "\n - " . implode ("\n - " , $ values );
4867 }
4968
5069 switch (intval ($ value ->getType ())) {
0 commit comments