7
7
use Symfony \Component \Console \Output \OutputInterface ;
8
8
use Symfony \Component \Console \Input \InputArgument ;
9
9
use Symfony \Component \Console \Input \InputOption ;
10
+ use PHPCR \PropertyType ;
10
11
11
12
class NodeListCommand extends Command
12
13
{
@@ -24,8 +25,14 @@ protected function configure()
24
25
$ this ->addOption ('properties ' , null , InputOption::VALUE_NONE , 'List only the properties of this node ' );
25
26
$ this ->addOption ('filter ' , 'f ' , InputOption::VALUE_REQUIRED |InputOption::VALUE_IS_ARRAY , 'Optional filter to apply ' );
26
27
$ 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 ' );
27
29
$ this ->setHelp (<<<HERE
28
30
List 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.
29
36
HERE
30
37
);
31
38
}
@@ -72,9 +79,20 @@ private function renderChildren($currentNode, $table, $spacers)
72
79
{
73
80
$ children = $ currentNode ->getNodes ($ this ->filters ? : null );
74
81
82
+ $ nodeType = $ currentNode ->getPrimaryNodeType ();
83
+ $ childNodeDefinitions = $ nodeType ->getDeclaredChildNodeDefinitions ();
84
+ $ childNodeNames = array ();
85
+ foreach ($ childNodeDefinitions as $ childNodeDefinition ) {
86
+ $ childNodeNames [$ childNodeDefinition ->getName ()] = $ childNodeDefinition ;
87
+ }
88
+
75
89
$ i = 0 ;
76
90
foreach ($ children as $ child ) {
77
91
$ i ++;
92
+ if (isset ($ childNodeNames [$ child ->getName ()])) {
93
+ unset($ childNodeNames [$ child ->getName ()]);
94
+ }
95
+
78
96
$ isLast = count ($ children ) === $ i ;
79
97
80
98
$ table ->addRow (array (
@@ -94,20 +112,50 @@ private function renderChildren($currentNode, $table, $spacers)
94
112
$ this ->renderNode ($ child , $ table , $ newSpacers );
95
113
}
96
114
}
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
+ }
97
125
}
98
126
99
127
private function renderProperties ($ currentNode , $ table , $ spacers )
100
128
{
101
129
$ properties = $ currentNode ->getProperties ($ this ->filters ? : null );
102
130
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
+
103
139
$ i = 0 ;
104
140
foreach ($ properties as $ name => $ property ) {
105
141
$ i ++;
142
+ if (isset ($ propertyNames [$ name ])) {
143
+ unset($ propertyNames [$ name ]);
144
+ }
145
+
106
146
$ table ->addRow (array (
107
147
'<property> ' . implode ('' , $ spacers ). $ name . '</property> ' ,
108
148
'<property-type> ' . $ this ->formatter ->getPropertyTypeName ($ property ->getType ()) . '</property-type> ' ,
109
149
$ this ->textHelper ->truncate ($ this ->formatter ->formatValue ($ property ), 55 ),
110
150
));
111
151
}
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
+ }
112
160
}
113
161
}
0 commit comments