77use Symfony \Component \Console \Output \OutputInterface ;
88use Symfony \Component \Console \Input \InputArgument ;
99use Symfony \Component \Console \Input \InputOption ;
10+ use PHPCR \PropertyType ;
1011
1112class NodeListCommand extends Command
1213{
@@ -24,8 +25,14 @@ protected function configure()
2425 $ this ->addOption ('properties ' , null , InputOption::VALUE_NONE , 'List only the properties of this node ' );
2526 $ this ->addOption ('filter ' , 'f ' , InputOption::VALUE_REQUIRED |InputOption::VALUE_IS_ARRAY , 'Optional filter to apply ' );
2627 $ this ->addOption ('level ' , 'L ' , InputOption::VALUE_REQUIRED , 'Depth of tree to show ' );
28+ $ this ->addOption ('no-template ' , 'T ' , InputOption::VALUE_REQUIRED , 'Do not show template nodes and properties ' );
2729 $ this ->setHelp (<<<HERE
2830List both or one of the children and properties of this node.
31+
32+ Multiple levels can be shown by using the <info>--level</info> option.
33+
34+ The <info>node:list</info> command also shows template nodes and properties as defined a nodes node-type.
35+ These can be suppressed using the <info>--no-template</info> option.
2936HERE
3037 );
3138 }
@@ -72,9 +79,20 @@ private function renderChildren($currentNode, $table, $spacers)
7279 {
7380 $ children = $ currentNode ->getNodes ($ this ->filters ? : null );
7481
82+ $ nodeType = $ currentNode ->getPrimaryNodeType ();
83+ $ childNodeDefinitions = $ nodeType ->getDeclaredChildNodeDefinitions ();
84+ $ childNodeNames = array ();
85+ foreach ($ childNodeDefinitions as $ childNodeDefinition ) {
86+ $ childNodeNames [$ childNodeDefinition ->getName ()] = $ childNodeDefinition ;
87+ }
88+
7589 $ i = 0 ;
7690 foreach ($ children as $ child ) {
7791 $ i ++;
92+ if (isset ($ childNodeNames [$ child ->getName ()])) {
93+ unset($ childNodeNames [$ child ->getName ()]);
94+ }
95+
7896 $ isLast = count ($ children ) === $ i ;
7997
8098 $ table ->addRow (array (
@@ -94,20 +112,50 @@ private function renderChildren($currentNode, $table, $spacers)
94112 $ this ->renderNode ($ child , $ table , $ newSpacers );
95113 }
96114 }
115+
116+ // render empty schematic children
117+ foreach ($ childNodeNames as $ childNodeName => $ childNodeDefinition ) {
118+ // @todo: Determine and show cardinality, 1..*, *..*, 0..1, etc.
119+ $ table ->addRow (array (
120+ '<templatenode> ' . implode ('' , $ spacers ) . '@ ' . $ childNodeName . '</templatenode> ' ,
121+ implode ('| ' , $ childNodeDefinition ->getRequiredPrimaryTypeNames ()),
122+ '' ,
123+ ));
124+ }
97125 }
98126
99127 private function renderProperties ($ currentNode , $ table , $ spacers )
100128 {
101129 $ properties = $ currentNode ->getProperties ($ this ->filters ? : null );
102130
131+ $ nodeType = $ currentNode ->getPrimaryNodeType ();
132+ $ propertyDefinitions = $ nodeType ->getDeclaredPropertyDefinitions ();
133+
134+ $ propertyNames = array ();
135+ foreach ($ propertyDefinitions as $ name => $ propertyDefinition ) {
136+ $ propertyNames [$ propertyDefinition ->getName ()] = $ propertyDefinition ;
137+ }
138+
103139 $ i = 0 ;
104140 foreach ($ properties as $ name => $ property ) {
105141 $ i ++;
142+ if (isset ($ propertyNames [$ name ])) {
143+ unset($ propertyNames [$ name ]);
144+ }
145+
106146 $ table ->addRow (array (
107147 '<property> ' . implode ('' , $ spacers ). $ name . '</property> ' ,
108148 '<property-type> ' . $ this ->formatter ->getPropertyTypeName ($ property ->getType ()) . '</property-type> ' ,
109149 $ this ->textHelper ->truncate ($ this ->formatter ->formatValue ($ property ), 55 ),
110150 ));
111151 }
152+
153+ foreach ($ propertyNames as $ propertyName => $ property ) {
154+ $ table ->addRow (array (
155+ '<templateproperty> ' . implode ('' , $ spacers ). '@ ' . $ propertyName . '</templateproperty> ' ,
156+ '<property-type> ' . strtoupper (PropertyType::nameFromValue ($ property ->getRequiredType ())) . '</property-type> ' ,
157+ ''
158+ ));
159+ }
112160 }
113161}
0 commit comments