@@ -12,6 +12,8 @@ class NodeListCommand extends Command
1212{
1313 protected $ formatter ;
1414 protected $ filters ;
15+ protected $ textHelper ;
16+ protected $ maxLevel ;
1517
1618 protected function configure ()
1719 {
@@ -21,6 +23,7 @@ protected function configure()
2123 $ this ->addOption ('children ' , null , InputOption::VALUE_NONE , 'List only the children of this node ' );
2224 $ this ->addOption ('properties ' , null , InputOption::VALUE_NONE , 'List only the properties of this node ' );
2325 $ this ->addOption ('filter ' , 'f ' , InputOption::VALUE_REQUIRED |InputOption::VALUE_IS_ARRAY , 'Optional filter to apply ' );
26+ $ this ->addOption ('level ' , 'L ' , InputOption::VALUE_REQUIRED , 'Depth of tree to show ' );
2427 $ this ->setHelp (<<<HERE
2528List both or one of the children and properties of this node.
2629HERE
@@ -32,53 +35,76 @@ public function execute(InputInterface $input, OutputInterface $output)
3235 $ this ->formatter = $ this ->getHelper ('result_formatter ' );
3336 $ this ->textHelper = $ this ->getHelper ('text ' );
3437 $ this ->filters = $ input ->getOption ('filter ' );
38+ $ this ->maxLevel = $ input ->getOption ('level ' );
3539
36- $ showChildren = $ input ->getOption ('children ' );
37- $ showProperties = $ input ->getOption ('properties ' );
40+ $ this -> showChildren = $ input ->getOption ('children ' );
41+ $ this -> showProperties = $ input ->getOption ('properties ' );
3842
3943 $ session = $ this ->getHelper ('phpcr ' )->getSession ();
4044
4145 $ path = $ session ->getAbsPath ($ input ->getArgument ('path ' ));
4246 $ currentNode = $ session ->getNode ($ path );
4347
44- if (!$ showChildren && !$ showProperties ) {
45- $ showChildren = true ;
46- $ showProperties = true ;
48+ if (!$ this -> showChildren && !$ this -> showProperties ) {
49+ $ this -> showChildren = true ;
50+ $ this -> showProperties = true ;
4751 }
4852
4953 $ table = clone $ this ->getHelper ('table ' );
5054
51- if ($ showChildren ) {
52- $ this ->renderChildren ($ currentNode , $ table );
53- }
55+ $ this ->renderNode ($ currentNode , $ table );
5456
55- if ($ showProperties ) {
56- $ this ->renderProperties ($ currentNode , $ table );
57+ $ table ->render ($ output );
58+ }
59+
60+ private function renderNode ($ currentNode , $ table , $ spacers = array ())
61+ {
62+ if ($ this ->showChildren ) {
63+ $ this ->renderChildren ($ currentNode , $ table , $ spacers );
5764 }
5865
59- $ table ->render ($ output );
66+ if ($ this ->showProperties ) {
67+ $ this ->renderProperties ($ currentNode , $ table , $ spacers );
68+ }
6069 }
6170
62- private function renderChildren ($ currentNode , $ table )
71+ private function renderChildren ($ currentNode , $ table, $ spacers )
6372 {
6473 $ children = $ currentNode ->getNodes ($ this ->filters ? : null );
6574
75+ $ i = 0 ;
6676 foreach ($ children as $ child ) {
77+ $ i ++;
78+ $ isLast = count ($ children ) === $ i ;
79+
6780 $ table ->addRow (array (
68- '<node> ' . $ this ->formatter ->formatNodeName ($ child ) . '</node> ' ,
81+ '<node> ' . implode ( '' , $ spacers ) . $ this ->formatter ->formatNodeName ($ child ) . '</node> ' ,
6982 $ child ->getPrimaryNodeType ()->getName (),
7083 '' ,
7184 ));
85+
86+ if (count ($ spacers ) < $ this ->maxLevel ) {
87+ $ newSpacers = $ spacers ;
88+ if ($ isLast ) {
89+ $ newSpacers [] = ' ' ;
90+ } else {
91+ $ newSpacers [] = '| ' ;
92+ }
93+
94+ $ this ->renderNode ($ child , $ table , $ newSpacers );
95+ }
7296 }
7397 }
7498
75- private function renderProperties ($ currentNode , $ table )
99+ private function renderProperties ($ currentNode , $ table, $ spacers )
76100 {
77101 $ properties = $ currentNode ->getProperties ($ this ->filters ? : null );
78102
103+ $ i = 0 ;
79104 foreach ($ properties as $ name => $ property ) {
105+ $ i ++;
80106 $ table ->addRow (array (
81- '<property> ' . $ name . '</property> ' ,
107+ '<property> ' . implode ( '' , $ spacers ). $ name . '</property> ' ,
82108 '<property-type> ' . $ this ->formatter ->getPropertyTypeName ($ property ->getType ()) . '</property-type> ' ,
83109 $ this ->textHelper ->truncate ($ this ->formatter ->formatValue ($ property ), 55 ),
84110 ));
0 commit comments